-
Notifications
You must be signed in to change notification settings - Fork 175
feat(otel): add support for opentelemetry logs #3748
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
rachelyangdog
wants to merge
4
commits into
master
Choose a base branch
from
rachel.yang/otel-logs
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
556c3b5
WIP feat(otel): add support for opentelemetry logs
rachelyangdog c5de9b5
revert submodule bumps to origin/master
rachelyangdog 5e7dc32
update hostname config
rachelyangdog d0b32bc
Merge branch 'master' into rachel.yang/otel-logs
rachelyangdog File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,21 +1,29 @@ | ||
| <?php | ||
|
|
||
| use DDTrace\OpenTelemetry\Detectors\DetectorHelper; | ||
| use OpenTelemetry\SDK\Common\Attribute\AttributesFactory; | ||
| use OpenTelemetry\SDK\Resource\ResourceInfo; | ||
|
|
||
| \DDTrace\install_hook( | ||
| 'OpenTelemetry\SDK\Resource\Detectors\Host::getResource', | ||
| null, | ||
| function (\DDTrace\HookData $hook) { | ||
| $attributes = []; | ||
|
|
||
| if (\dd_trace_env_config('DD_TRACE_REPORT_HOSTNAME')) { | ||
| $ddHostname = \dd_trace_env_config('DD_HOSTNAME'); | ||
| // Only override if DD_HOSTNAME is explicitly set to avoid | ||
| // clobbering the hostname detected by OTel's Host detector | ||
| if ($ddHostname !== '') { | ||
| $attributes['host.name'] = $ddHostname; | ||
| DetectorHelper::mergeAttributes($hook, ['host.name' => $ddHostname]); | ||
| } | ||
| return; | ||
| } | ||
|
|
||
| DetectorHelper::mergeAttributes($hook, $attributes); | ||
| }); | ||
| // DD_TRACE_REPORT_HOSTNAME is not set — strip auto-detected host.name so it | ||
| // doesn't appear in logs unless explicitly set in OTEL_RESOURCE_ATTRIBUTES. | ||
| $filtered = []; | ||
| foreach ($hook->returned->getAttributes() as $key => $value) { | ||
| if ($key !== 'host.name') { | ||
| $filtered[$key] = $value; | ||
| } | ||
| } | ||
| $builder = (new AttributesFactory())->builder($filtered); | ||
| $hook->overrideReturnValue(ResourceInfo::create($builder->build(), $hook->returned->getSchemaUrl())); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| <?php | ||
|
|
||
| // This file installs hooks that improve OTLP export reliability: | ||
| // 1. A one-time actionable warning when the Datadog Agent returns HTTP 404 | ||
| // (i.e. Agent < 7.48.0 that does not support OTLP ingest) | ||
| // 2. A graceful fallback to 'http/protobuf' when an unrecognized protocol | ||
| // value reaches Protocols::contentType(), preventing an uncaught | ||
| // UnexpectedValueException from silently killing all exports | ||
|
|
||
| // One-time 404 warning --------------------------------------------------- | ||
| // PsrTransport wraps 4xx (non-408/429) errors in ErrorFuture. Peek at the | ||
| // stored exception via reflection so we can emit a human-actionable message | ||
| // once, without modifying the future that the caller receives. | ||
| \DDTrace\install_hook( | ||
| 'OpenTelemetry\SDK\Common\Export\Http\PsrTransport::send', | ||
| null, | ||
| function (\DDTrace\HookData $hook) { | ||
| $future = $hook->returned; | ||
| if (!($future instanceof \OpenTelemetry\SDK\Common\Future\ErrorFuture)) { | ||
| return; | ||
| } | ||
|
|
||
| try { | ||
| $r = new \ReflectionProperty(\OpenTelemetry\SDK\Common\Future\ErrorFuture::class, 'throwable'); | ||
| $r->setAccessible(true); | ||
| $e = $r->getValue($future); | ||
| } catch (\Throwable $ignored) { | ||
| return; | ||
| } | ||
|
|
||
| if (!($e instanceof \RuntimeException) || $e->getCode() !== 404) { | ||
| return; | ||
| } | ||
|
|
||
| static $warned404 = false; | ||
| if (!$warned404) { | ||
| $warned404 = true; | ||
| trigger_error( | ||
| 'Datadog OpenTelemetry OTLP export received HTTP 404 Not Found. ' | ||
| . 'Ensure Datadog Agent >= 7.48.0 is running and configured to accept OTLP data ' | ||
| . '(set DD_OTLP_CONFIG_RECEIVER_PROTOCOLS_HTTP_ENDPOINT or equivalent).', | ||
| E_USER_WARNING | ||
| ); | ||
| } | ||
| } | ||
| ); | ||
|
|
||
| // Protocol fallback ------------------------------------------------------- | ||
| // The OTel SDK's Protocols::contentType() calls validate() which throws | ||
| // UnexpectedValueException for unknown protocols. We replace an invalid value | ||
| // with 'http/protobuf' before the method body runs, emitting a one-time | ||
| // warning so the user knows their configuration was ignored. | ||
| \DDTrace\install_hook( | ||
| 'OpenTelemetry\Contrib\Otlp\Protocols::contentType', | ||
| function (\DDTrace\HookData $hook) { | ||
| $protocol = $hook->args[0] ?? null; | ||
| if ($protocol === null) { | ||
| return; | ||
| } | ||
|
|
||
| static $valid = ['grpc', 'http/protobuf', 'http/json', 'http/ndjson']; | ||
| if (in_array($protocol, $valid, true)) { | ||
| return; | ||
| } | ||
|
|
||
| static $warnedProtocol = false; | ||
| if (!$warnedProtocol) { | ||
| $warnedProtocol = true; | ||
| trigger_error( | ||
| "OpenTelemetry OTLP protocol '$protocol' is not recognized. " | ||
| . "Valid values are: grpc, http/protobuf, http/json, http/ndjson. " | ||
| . "Falling back to 'http/protobuf'.", | ||
| E_USER_WARNING | ||
| ); | ||
| } | ||
|
|
||
| $hook->args[0] = 'http/protobuf'; | ||
| } | ||
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When only
DD_LOGS_OTEL_ENABLED=trueis set, this makesOTEL_PHP_AUTOLOAD_ENABLEDresolve to true, and the OpenTelemetry PHP autoloader initializes tracer, meter, and logger providers together. Because this resolver does not also forceOTEL_TRACES_EXPORTERandOTEL_METRICS_EXPORTERtonone, their SDK defaults remainotlp, so enabling Datadog's OTel logs mode can also start exporting traces and metrics for applications that did not opt into those signals.Useful? React with 👍 / 👎.