open-telemetry / opentelemetry-rust

The Rust OpenTelemetry implementation
https://opentelemetry.io
Apache License 2.0
1.88k stars 438 forks source link

resource attributes not present #1261

Open casualjim opened 1 year ago

casualjim commented 1 year ago

I have 2 identical configurations, 1 in golang and 1 in rust.

In golang when I specify attributes in resource I see them appear in zipkin but for the rust version those attributes are missing. From just looking at the code that should not be the case.

Rust config:

Golang:

casualjim commented 1 year ago

It appears that the resource is never added to the attributes in the exporter. Adding

.chain(
    span_data
        .resource
        .as_ref()
        .iter()
        .map(|(k, v)| KeyValue::new(k.clone(), v.clone())),
)

here fixes the issue.

I took a look at the codebase and this seems to be a consistent omission, is there a reason for that?

cijothomas commented 1 year ago

The spec does not cover what to do with Resource for Zipkin. https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/sdk_exporters/zipkin.md

In general, Resource should not be automatically added as Span Attributes - some exporters may chose to do that, depending on their backends.

Were you expecting that all Resource attributes are added as Span attributes? If yes, Zipkin exporter could add a feature to do that if use opts-in to such a feature. (I dont think the Collector's Zipkin Exporter is doing this either..https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/exporter/zipkinexporter/factory.go)

casualjim commented 1 year ago

They do add them everywhere: https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/pkg/translator/zipkin/zipkinv2/from_translator.go#L60-L61

cijothomas commented 1 year ago

They do add them everywhere: https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/pkg/translator/zipkin/zipkinv2/from_translator.go#L60-L61

Got it. (Note that it is not a stable component, and that is not the spec).

What I said is still true - Resource should not automatically be added as Span attributes by default.

hdost commented 8 months ago

It appears a similar conversation is happening in the spec https://github.com/open-telemetry/opentelemetry-specification/issues/1196