Skip to content

Fix WithSpanHandler: remove hardcode, add constants instead#1927

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

Fix WithSpanHandler: remove hardcode, add constants instead#1927
mdomansky wants to merge 5 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.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 22, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 67.26%. Comparing base (938c2bc) to head (9efbcfb).
⚠️ Report is 5 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##               main    #1927      +/-   ##
============================================
- Coverage     68.29%   67.26%   -1.04%     
- Complexity     3009     3022      +13     
============================================
  Files           449      450       +1     
  Lines          8798     9139     +341     
============================================
+ Hits           6009     6147     +138     
- Misses         2789     2992     +203     
Flag Coverage Δ
8.1 ?
8.2 ?
8.3 ?
8.4 ?
8.5 67.26% <100.00%> (-0.13%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/API/Instrumentation/WithSpanHandler.php 90.00% <100.00%> (-0.33%) ⬇️

... and 218 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 938c2bc...9efbcfb. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

->setAttribute('code.namespace', $class)
->setAttribute('code.filepath', $filename)
->setAttribute('code.lineno', $lineno)
->setAttribute('code.function.name', $class !== null ? $class . '::' . $function : $function)
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.

Could unify this with the span $name logic above:

$functionName = $class !== null ? $class . '::' . $function : $function;
$name = $span_args['name'] ?? $functionName;

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