Skip to content
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

Distributed tracing by CLI scripts #1142

Open
bram123 opened this issue Mar 18, 2024 · 1 comment
Open

Distributed tracing by CLI scripts #1142

bram123 opened this issue Mar 18, 2024 · 1 comment

Comments

@bram123
Copy link

bram123 commented Mar 18, 2024

Is your feature request related to a problem? Please describe.
We would like to add distributed tracing to CLI scripts. We have a scheduler process that starts separate PHP processes. This scheduler reports back runtime status among other things.
It would be great if we can pass the traceId + transactionId of the scheduler script, to the new PHP processes. Where it would be set as traceId + parentId.

Describe the solution you'd like
The extension not only looks for request headers, but also for an ENV var.
This way we can pass the tracecontext of the scheduler script to the new spawned processes.

@zobo
Copy link
Contributor

zobo commented Jan 17, 2025

I finally came back to this to see it was actually working as expected - at least for my case.

We can see here

$traceParentHeaderValue = $this->getHttpHeader(HttpDistributedTracing::TRACE_PARENT_HEADER_NAME);
that the code is looking up TRACEPARENT header from $_SERVER. Here and here
return isset($_SERVER[$key]) ? $_SERVER[$key] : null;
.

So in our scheduler (written in Go) we compute the distributed tracing value and pass it to the child process like this:

cmd := exec.Command(entrypoint, s.Arguments...)
cmd.Env = os.Environ()
c := tx.TraceContext()
c.Options = c.Options.WithRecorded(true)
tp := fmt.Sprintf("%02x-%032x-%016x-%02x", 0, c.Trace[:], c.Span[:], c.Options)
cmd.Env = append(cmd.Env, "TRACEPARENT="+tp, "HTTP_TRACEPARENT="+tp)

PHP will read the HTTP_TRACEPARENT value.

Now, I know this is a workaround, but it does what I need...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants