Skip to content

Commit

Permalink
Add log-injection example
Browse files Browse the repository at this point in the history
- Remove ngx.var
- config.service is not required anymore
  • Loading branch information
dmehala committed May 30, 2024
1 parent 129769f commit cd7a91b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
9 changes: 4 additions & 5 deletions kong/plugins/ddtrace/handler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,13 @@ end
local function expose_tracing_variables(span)
-- Expose traceID and parentID for other plugin to consume and also set an NGINX variable
-- that can be use for in `log_format` directive for correlation with logs.
-- NOTE: kong.ctx has the same lifetime as the current request.
local trace_id = btohex(span.trace_id.high or 0, 16) .. btohex(span.trace_id.low, 16)
local span_id = btohex(span.span_id, 16)

kong.ctx.shared.datadog_sdk_trace_id = trace_id
kong.ctx.shared.datadog_sdk_span_id = span_id
ngx.var.datadog_sdk_trace_id = trace_id
ngx.var.datadog_sdk_span_id = span_id
-- NOTE: kong.ctx has the same lifetime as the current request.
local kong_shared = kong.ctx.shared
kong_shared.datadog_sdk_trace_id = trace_id
kong_shared.datadog_sdk_span_id = span_id
end

-- adds the proxy span to the datadog context, unless it already exists
Expand Down
2 changes: 1 addition & 1 deletion kong/plugins/ddtrace/schema.lua
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ return {
config = {
type = "record",
fields = {
{ service_name = { type = "string", required = true } },
{ service_name = { type = "string" } },
{ environment = { type = "string" } },
-- priority of values for agent address details are resolved in new_trace_agent_writer
{ agent_host = typedefs.host({}) },
Expand Down

0 comments on commit cd7a91b

Please sign in to comment.