Skip to content

otel_span_attr from different levels are not merged #107

@danielkatz

Description

@danielkatz

Describe the bug

When otel_span_attr directives are declared at both the http level and the server (or location) level, only one group of attributes is reported in the span—not both. The attributes are not merged; instead, the child context's attributes completely replace the parent's.

To reproduce

  1. Configure nginx with otel_span_attr at both http and server levels:
http {
    otel_exporter {
        endpoint localhost:4317;
    }

    otel_trace on;
    otel_span_attr http.level "from-http";

    server {
        listen 8080;
        otel_span_attr server.level "from-server";

        location / {
            return 200 "ok";
        }
    }
}
  1. Send a request to the server
  2. Inspect the exported span attributes

Actual result: Only server.level attribute is present.

Expected behavior

Both http.level and server.level attributes should be present in the span. Attributes declared at different configuration levels should be merged, with child levels potentially overriding parent values for the same attribute name.

Your environment

  • Version/release: nginx/1.29.4
  • Target deployment platform: container base on alpine:3.22

Additional context

The issue is in mergeLocationConf in src/http_module.cpp:

if (conf->spanAttrs.elts == NULL) {
    conf->spanAttrs = prev->spanAttrs;
}

This logic only inherits parent attributes when the child has none. If the child has any otel_span_attr directives, the parent's attributes are silently discarded rather than merged.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions