-
Notifications
You must be signed in to change notification settings - Fork 191
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
[opentelemetry-php-contrib] Automatically associate monolog record to the current trace from context #1441
Comments
Hi @DominicDetta there is some configuration required for that package, and it's not clear whether you have done it or not. You need to create a handler and configure monolog to use it, and the otel logger provider can be either manually or automatically created. Have you tried something like in the examples? |
Hi, this is the code added to the monolog class: $logger = new Logger('formflow');
/* extra code */
// Opentelemetry
$openTelemetryHandler = new Handler(
Globals::loggerProvider(),
LogLevel::INFO,
true,
);
$logger->pushHandler($streamHandler);
$logger->pushHandler($handler);
$logger->pushHandler($openTelemetryHandler); I verified whether the log is sent to Opentelemetry correctly and I can confirm the problem reside already in the instrumentation, as you can see the attributes trace_id and span_id are empty: 2024-11-28 11:24:29 {
2024-11-28 11:24:29 "resource": {
2024-11-28 11:24:29 "attributes": {
2024-11-28 11:24:29 "host.name": "f78b98028f84",
2024-11-28 11:24:29 "host.arch": "x86_64",
2024-11-28 11:24:29 "os.type": "linux",
2024-11-28 11:24:29 "os.description": "6.6.26-linuxkit",
2024-11-28 11:24:29 "os.name": "Linux",
2024-11-28 11:24:29 "os.version": "#1 SMP Sat Apr 27 04:13:19 UTC 2024",
2024-11-28 11:24:29 "process.pid": 117,
2024-11-28 11:24:29 "process.executable.path": "",
2024-11-28 11:24:29 "process.owner": "www-data",
2024-11-28 11:24:29 "process.runtime.name": "apache2handler",
2024-11-28 11:24:29 "process.runtime.version": "8.3.14",
2024-11-28 11:24:29 "telemetry.sdk.name": "opentelemetry",
2024-11-28 11:24:29 "telemetry.sdk.language": "php",
2024-11-28 11:24:29 "telemetry.sdk.version": "1.0.8",
2024-11-28 11:24:29 "telemetry.distro.name": "opentelemetry-php-instrumentation",
2024-11-28 11:24:29 "telemetry.distro.version": "1.1.0",
2024-11-28 11:24:29 "service.name": "formflow-demo",
2024-11-28 11:24:29 "service.version": "1.11.10"
2024-11-28 11:24:29 },
2024-11-28 11:24:29 "dropped_attributes_count": 0
2024-11-28 11:24:29 },
2024-11-28 11:24:29 "scopes": [
2024-11-28 11:24:29 {
2024-11-28 11:24:29 "name": "formflow",
2024-11-28 11:24:29 "version": null,
2024-11-28 11:24:29 "attributes": [],
2024-11-28 11:24:29 "dropped_attributes_count": 0,
2024-11-28 11:24:29 "schema_url": null,
2024-11-28 11:24:29 "logs": [
2024-11-28 11:24:29 {
2024-11-28 11:24:29 "timestamp": 1732789469476225000,
2024-11-28 11:24:29 "observed_timestamp": 1732789469494023168,
2024-11-28 11:24:29 "severity_number": 18,
2024-11-28 11:24:29 "severity_text": "CRITICAL",
2024-11-28 11:24:29 "body": "Exception: asdsads....",
2024-11-28 11:24:29 "trace_id": "00000000000000000000000000000000",
2024-11-28 11:24:29 "span_id": "0000000000000000",
2024-11-28 11:24:29 "trace_flags": 0,
2024-11-28 11:24:29 "attributes": {
2024-11-28 11:24:29 },
2024-11-28 11:24:29 "dropped_attributes_count": 0
2024-11-28 11:24:29 }
2024-11-28 11:24:29 ]
2024-11-28 11:24:29 }
2024-11-28 11:24:29 ] |
Maybe the exception is triggered before the instrumentation is able to create the trace id? |
That's a good point - it could be that the error is logged either before or after the trace. Do you use auto-instrumentation or manual in your code? |
I'm using the
open-telemetry/opentelemetry-logger-monolog
package but log records generated are not related to request trace.Following is a screenshot from the Signoz monitoring solution:
Is this a bug or a normal behaviour?
Without the trace_id the APM is not able to navigate automatically to the associated request trace.
From the example of this page I think it should be possible to inject the trace and span id automatically
The text was updated successfully, but these errors were encountered: