Skip to content

Fix WithSpanHandler: remove hardcode, add constants instead#1927

Open
mdomansky wants to merge 4 commits intoopen-telemetry:mainfrom
mdomansky:with-span-handler-fix
Open

Fix WithSpanHandler: remove hardcode, add constants instead#1927
mdomansky wants to merge 4 commits intoopen-telemetry:mainfrom
mdomansky:with-span-handler-fix

Conversation

@mdomansky
Copy link
Copy Markdown

@mdomansky mdomansky commented Mar 25, 2026

I have a list of containers:
1 - my php app
2 - otel-collector
3 - opensearch

While using #[WithSpan] attribute on methods on my php container, all span information is successfully sent to the otel-collector container, but while the last sends the info to the opensearch database I get an exception:

error internal/base_exporter.go:115 Exporting failed. Rejecting data. Try enabling sending_queue to survive temporary failures. {"resource": {"[service.instance.id](http://service.instance.id/)": "c614aac8-2cfa-48f9-b109-a246a99f80ad", "[service.name](http://service.name/)": "otelcol-contrib", "service.version": "0.145.0"}, "[otelcol.component.id](http://otelcol.component.id/)": "opensearch", "otelcol.component.kind": "exporter", "otelcol.signal": "traces", "error": "not retryable error: Permanent error: {\"type\":\"mapper_parsing_exception\",\"reason\":\"object mapping for [attributes.code.function] tried to parse field [code.function] as object, but found a concrete value\",\"caused_by\":{\"type\":\"\",\"reason\":\"\",\"caused_by\":null}}", "rejected_items": 7}

My env:

OTEL_ENABLED: 'true'
OTEL_TRACES_EXPORTER: 'otlp'

Having researched, I found that "wrong" attribute names are hardcoded, so I updated them with constants.

@mdomansky mdomansky requested a review from a team as a code owner March 25, 2026 14:37
@linux-foundation-easycla
Copy link
Copy Markdown

linux-foundation-easycla Bot commented Mar 25, 2026

CLA Signed

The committers listed above are authorized under a signed CLA.

Copy link
Copy Markdown
Contributor

@ChrisLightfootWild ChrisLightfootWild left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is intentionally hardcoded to avoid the dependency on SemConv in the API package.

@mdomansky
Copy link
Copy Markdown
Author

This is intentionally hardcoded to avoid the dependency on SemConv in the API package.

Why do I get the issue like code.function is wrong while code.function.name is correct?

@ChrisLightfootWild
Copy link
Copy Markdown
Contributor

This is intentionally hardcoded to avoid the dependency on SemConv in the API package.

Why do I get the issue like code.function is wrong while code.function.name is correct?

I believe code.function is correct for the emitted version of telemetry, 1.25.0. See https://github.com/open-telemetry/semantic-conventions/blob/v1.25.0/model/general.yaml#L55-L65

Might be worth asking the otel collector devs on this one. The schema file links to open-telemetry/semantic-conventions#1624 from the 1.30.0 semantic conventions. It contains the following:

...trimmed
  1.30.0:
    all:
      changes:
...trimmed
        - rename_attributes:
            attribute_map:
              code.function: code.function.name
              code.filepath: code.file.path
              code.lineno: code.line.number
              code.column: code.column.number

My understanding is that we are emitting valid telemetry for the schema version we have declared, and that the collector should rename the attributes during ingestion.

@bobstrecansky
Copy link
Copy Markdown
Contributor

@open-telemetry/collector-approvers, can you weigh in here?

@bobstrecansky bobstrecansky added the blocked this issue is blocked by another issue. label Apr 8, 2026
@mx-psi
Copy link
Copy Markdown
Member

mx-psi commented Apr 8, 2026

The error on this PR's description seems specific to the opensearch exporter, feel free to file an issue on the opentelemetry-collector-contrib bug tracker and the code owners will take a look

@mdomansky
Copy link
Copy Markdown
Author

Updated the schema version and updated span attribute names according to the scheme. Left hardcoded attribute names.

Comment thread src/API/Instrumentation/WithSpanHandler.php Outdated
Co-authored-by: Tobias Bachert <github.dev.k9ps1@mail.tobiasbachert.com>
->setAttribute('code.function.name', $class !== null ? $class . '::' . $function : $function)
->setAttribute('code.file.path', $filename)
->setAttribute('code.line.number', $lineno)
->setAttribute('code.column.number', $lineno)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't look right. I don't think we should use the line number as column number.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

blocked this issue is blocked by another issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants