skywalking icon indicating copy to clipboard operation
skywalking copied to clipboard

[Feature] Expose traceId in PHP for Enhanced Observability

Open warshipJian opened this issue 1 year ago • 5 comments

Search before asking

  • [X] I had searched in the issues and found no similar feature requirement.

Description

I've been using SkyWalking for monitoring and tracing in both Java and PHP environments. One thing I noticed is that in Java, it's straightforward to use traceId for correlating logs and traces, which is super helpful for debugging and observability.

However, in PHP, there doesn't seem to be a straightforward way to access or expose the traceId within the application. This makes it a bit challenging to link logs with traces directly, which is something I believe could greatly benefit PHP developers focused on improving application observability.

Is there any chance we could see a feature in the PHP agent that allows accessing the traceId directly from the PHP code? It would be a huge boost for logging and monitoring practices in PHP applications.

Use case

No response

Related issues

No response

Are you willing to submit a pull request to implement this on your own?

  • [ ] Yes I am willing to submit a pull request on my own!

Code of Conduct

warshipJian avatar Feb 18 '24 06:02 warshipJian

@jmjoy What do you think about this?

wu-sheng avatar Feb 18 '24 06:02 wu-sheng

Very good, but how to Expose traceId is worth discussing. What I think of is by injecting the $_SERVER variable for php-fpm, or $request->server for swoole.

jmjoy avatar Feb 18 '24 07:02 jmjoy

Is $_SW_TRACE_ID a valid and good variable name for PHP ecosystem?

wu-sheng avatar Feb 18 '24 07:02 wu-sheng

Is $_SW_TRACE_ID a valid and good variable name for PHP ecosystem?

I think it's ok

jmjoy avatar Feb 18 '24 08:02 jmjoy

In Java, we have trace ID and trace context variables, please refer to this

https://skywalking.apache.org/docs/skywalking-java/next/en/setup/service-agent/java-agent/application-toolkit-logback-1.x/#print-skywalking-context-in-your-logs

wu-sheng avatar Feb 18 '24 09:02 wu-sheng

We can add SW_TRACE_ID to $_SERVER

heyanlong avatar Feb 19 '24 06:02 heyanlong