ogen icon indicating copy to clipboard operation
ogen copied to clipboard

[Labelers Not adding attributes]: [Using the Labeler from the context attributes are not added to spans, only metrics]

Open vlurgio opened this issue 1 year ago • 0 comments

What version of ogen are you using?

ogen version v1.8.1 (built with go1.23.2) darwin/arm64

Can this issue be reproduced with the latest version?

Yes

What did you do?

Using the labeler from the context in handler functions does not add the custom attributes to the span.

Using a labeler like this

	labeler, ok := api.LabelerFromContext(ctx)
    if ok {
	    labeler.Add(
		    attribute.KeyValue{Key: "attr1", Value: attribute.StringValue(p.attr1)},
		    attribute.KeyValue{Key: "attr2", Value: attribute.StringValue(p.att2)},
	    )
    }

In the implemented interfaces fails as the following code in the generated handler layer has a bug in it.

		if code != 0 {
			codeAttr := semconv.HTTPResponseStatusCode(code)
			attrs = append(attrs, codeAttr)
			span.SetAttributes(codeAttr)
		}
		attrOpt := metric.WithAttributes(codeAttr)

should be

		if code != 0 {
			codeAttr := semconv.HTTPResponseStatusCode(code)
			attrs = append(attrs, codeAttr)
			span.SetAttributes(attrs...)
		}
		attrOpt := metric.WithAttributes(codeAttr)

right now it's using the unappended to list to set the attributes on the span. Would love to open a PR to fix this.

What did you expect to see?

Custom Attributes added to a span.

What did you see instead?

Attributes are not added to spans.

vlurgio avatar Feb 13 '25 19:02 vlurgio