open-telemetry / open-telemetry/opentelemetry-cpp-contrib
Access Span and Trace ID in Lua Script
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 153
- Forks
- 184
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 26
Description
I am using it with ingress-nginx (v 1.9.5) and have it set up like in the documentation: https://kubernetes.github.io/ingress-nginx/user-guide/third-party-addons/opentelemetry/
Unfortunately, to correlate the logs and traces with datadog, one needs to transform the log and span ids like described here:
https://docs.datadoghq.com/tracing/other_telemetry/connect_logs_and_traces/opentelemetry/?tab=python
So I created a lua plugin and use the log_by_lua block. However, the nginx variables are not set.
My code is:
-- simplified, it's actually called by the ingress-nginx plugin system, but the plugin is called from within log_by_lua
log_by_lua_block {
local trace_id = ngx.var.opentelemetry_trace_id
local span_id = ngx.var.opentelemetry_span_id
-- do the transformation according to the datadog documentation
ngx.var.trace_id=trace_id
ngx.var.span_id=span_id
}
I then access it in my logs via the $span_id and $trace_id variables.
However, ngx.var.opentelemetry_trace_id and ngx.var.opentelemetry_span_id is always nil.
If I manually set the variables like local trace_id='somevalue' it prints the correct value in the log.
- is
log_by_lua_blockthe correct place to get the values? When are they actually set by the plugin? - is
ngx.var.opentelemetry_trace_idthe place where I can find the variable? I also looked atngx.ctxbut couldn't find anything there.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the ingress-nginx OpenTelemetry documentation and the log_by_lua integration described in the issue. Trace when opentelemetry_trace_id and opentelemetry_span_id are exposed, then verify the documented access path and log output; done when the issue's questions have a reproducible answer.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- kubernetes, lua, nginx
- Domain
- observability
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100