Skip to content

Add BytesMapCarrier#2245

Closed
rakyll wants to merge 6 commits intoopen-telemetry:mainfrom
rakyll:map-carrier
Closed

Add BytesMapCarrier#2245
rakyll wants to merge 6 commits intoopen-telemetry:mainfrom
rakyll:map-carrier

Conversation

@rakyll
Copy link
Copy Markdown
Contributor

@rakyll rakyll commented Sep 16, 2021

BytesMapCarrier makes it easy for users to inject/extract propagated values from various sources. For example, if a trace context is propagated by an environment variable, users can create a new BytesMapCarrier with values from the environment and inject the trace context into a Go context.

Fixes #2243.

@codecov
Copy link
Copy Markdown

codecov Bot commented Sep 16, 2021

Codecov Report

Merging #2245 (878c1c7) into main (c577314) will increase coverage by 0.0%.
The diff coverage is 100.0%.

Impacted file tree graph

@@          Coverage Diff          @@
##            main   #2245   +/-   ##
=====================================
  Coverage   73.6%   73.6%           
=====================================
  Files        175     175           
  Lines      12409   12419   +10     
=====================================
+ Hits        9134    9147   +13     
+ Misses      3041    3039    -2     
+ Partials     234     233    -1     
Impacted Files Coverage Δ
propagation/propagation.go 85.7% <100.0%> (+4.4%) ⬆️
...s/otlp/otlptrace/internal/connection/connection.go 16.2% <0.0%> (+1.5%) ⬆️

@Aneurysm9 Aneurysm9 added area:propagators Part of OpenTelemetry context propagation enhancement New feature or request release:after-1.0 labels Sep 16, 2021
BytesMapCarrier makes it easy for users to inject/extract propagated values from various sources. For example, if a trace context is propagated by an environment variable, users can create a new BytesMapCarrier with values from the environment and inject the trace context into a Go context.
@pellared
Copy link
Copy Markdown
Member

Would it not be better if this propagator lives in OTel Go Contrib as it is not required not defined by the spec?

@Aneurysm9
Copy link
Copy Markdown
Member

Would it not be better if this propagator lives in OTel Go Contrib as it is not required not defined by the spec?

I don't think the HeaderCarrier we provide here is required by the spec either. I think this is worth having in the main propagation package rather than requiring users to import another module just for this broadly useful carrier.

Comment thread propagation/propagators_test.go Outdated
Copy link
Copy Markdown
Member

@Aneurysm9 Aneurysm9 left a comment

Choose a reason for hiding this comment

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

This generally looks good to me. Please fix the flaky test and add a CHANGELOG entry.

}

// Set stores the key-value pair.
func (c BytesMapCarrier) Set(key string, value string) {
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.

Why input the value as a string and store it as a []byte?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@jmacd So that it implements the TextMapCarrier interface.

@rakyll Maybe it would be worth adding var _ TextMapCarrier = (*BytesMapCarrier)(nil) ?

Copy link
Copy Markdown
Contributor

@jmacd jmacd Sep 21, 2021

Choose a reason for hiding this comment

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

Why not store the value as a string, vs. storing as a []byte?

Not blocking, just curiousity. It seems to mean that every call to Get() copies the []byte into a new string because the compiler can't tell that the []byte is never modified.

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.

@rakyll would you mind following up, here?

Comment thread propagation/propagation.go
Copy link
Copy Markdown
Member

@pellared pellared left a comment

Choose a reason for hiding this comment

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

Just a little proposal to make it more clear that BytesMapCarrier implements TextMapCarrier interface.

}

// Set stores the key-value pair.
func (c BytesMapCarrier) Set(key string, value string) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@jmacd So that it implements the TextMapCarrier interface.

@rakyll Maybe it would be worth adding var _ TextMapCarrier = (*BytesMapCarrier)(nil) ?

Comment on lines +43 to +44
// BytesMapCarrier is a Carrier that stores propagated
// values in a map of bytes.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
// BytesMapCarrier is a Carrier that stores propagated
// values in a map of bytes.
// BytesMapCarrier adapts map of bytes to satisfy the TextMapCarrier interface.

@rakyll
Copy link
Copy Markdown
Contributor Author

rakyll commented Oct 26, 2021

Is it ok for someone to take over this PR? I opened it but have no bandwidth to follow up right now.

@jmacd
Copy link
Copy Markdown
Contributor

jmacd commented Oct 27, 2021

@rakyll We had asked you a question: #2245 (comment)

@MrAlias
Copy link
Copy Markdown
Contributor

MrAlias commented Oct 28, 2021

Is it ok for someone to take over this PR? I opened it but have no bandwidth to follow up right now.

I'm happy to take this over, but I think to @jmacd's point we should probably replace this PR with a one adding a type StringMapCarrier map[string]string. I'll start work to open a PR to add that and potentially replace this.

@MrAlias MrAlias mentioned this pull request Oct 28, 2021
@MrAlias
Copy link
Copy Markdown
Contributor

MrAlias commented Oct 28, 2021

I've created #2334 as a replacement, please take a look.

pull Bot pushed a commit to Hawthorne001/opentelemetry-go that referenced this pull request Jul 16, 2025
Resolve open-telemetry#7030 

This generation fixes the following:

- The `semconv/weaver.yaml` file is moved to the
`semconv/templates/registry/go` to [fix the
generation](open-telemetry#7030 (comment)).
- Deprecated enum `var`s are no longer generate.
- The deprecation of the previous `OSTypeZOS` (`z_os`) conflicts with
the replacement (`zos`).
- This matches all other generations where deprecated types are not
generated and the migration docs identify users need to upgrade when
upgrading packages.
- Fix metric description rendering to handle multi-line metric
descriptions.
- Fix filter of deprecated metrics in weaver configuration (see
open-telemetry/weaver#847).

The release notes for v1.35.0 are included as we do not plan to add a
package for that release and it includes breaking changes being released
here (i.e. `az.namespace` and `az.service_request_id`)

## [`v1.36.0` semantic convention release
notes](https://github.com/open-telemetry/semantic-conventions/releases/tag/v1.36.0)

<div data-pjax="true" data-test-selector="body-content"
data-view-component="true" class="markdown-body my-3"><h3>🚩 Deprecations
🚩</h3>
<ul>
<li><code>os</code>: Adds the 'deprecated:' tag/attribute to the
<code>z_os</code> enum value of <code>os.type</code>. This value was
recently deprecated in v1.35.0. (<a
href="open-telemetry/semantic-conventions#2479"
data-hovercard-type="pull_request"
data-hovercard-url="/open-telemetry/semantic-conventions/pull/2479/hovercard"
aria-keyshortcuts="Alt+ArrowUp">open-telemetry#2479</a>)</li>
</ul>
<h3>💡 Enhancements 💡</h3>
<ul>
<li><code>otel</code>: Replaces <code>otel.sdk.span.ended</code> with
<code>otel.sdk.span.started</code> and allow differentiation based on
the parent span origin (<a
href="open-telemetry/semantic-conventions#2431"
data-hovercard-type="pull_request"
data-hovercard-url="/open-telemetry/semantic-conventions/pull/2431/hovercard"
aria-keyshortcuts="Alt+ArrowUp">open-telemetry#2431</a>)</li>
<li><code>db</code>: Add database context propagation via <code>SET
CONTEXT_INFO</code> for SQL Server (<a
href="open-telemetry/semantic-conventions#2162"
data-hovercard-type="issue"
data-hovercard-url="/open-telemetry/semantic-conventions/issues/2162/hovercard"
aria-keyshortcuts="Alt+ArrowUp">open-telemetry#2162</a>)</li>
<li><code>entities</code>: Adds support for Entity registry and Entity
stabilization policies. (<a
href="open-telemetry/semantic-conventions#2246"
data-hovercard-type="issue"
data-hovercard-url="/open-telemetry/semantic-conventions/issues/2246/hovercard"
aria-keyshortcuts="Alt+ArrowUp">open-telemetry#2246</a>)</li>
</ul>
<h3>🧰 Bug fixes 🧰</h3>
<ul>
<li><code>cloud</code>: Exclude deprecated Azure members from code
generation on the <code>cloud.platform</code> attribute (<a
href="open-telemetry/semantic-conventions#2477"
data-hovercard-type="pull_request"
data-hovercard-url="/open-telemetry/semantic-conventions/pull/2477/hovercard"
aria-keyshortcuts="Alt+ArrowUp">open-telemetry#2477</a>, <a
href="open-telemetry/semantic-conventions#2455"
data-hovercard-type="issue"
data-hovercard-url="/open-telemetry/semantic-conventions/issues/2455/hovercard"
aria-keyshortcuts="Alt+ArrowUp">open-telemetry#2455</a>)</li>
</ul>

## [`v1.35.0` semantic convention release
notes](https://github.com/open-telemetry/semantic-conventions/releases/tag/v1.35.0)

<div data-pjax="true" data-test-selector="body-content"
data-view-component="true" class="markdown-body my-3"><h3>🛑 Breaking
changes 🛑</h3>
<ul>
<li>
<p><code>azure</code>: Align azure events, attributes, and enum members
with general naming guidelines. (<a
href="open-telemetry/semantic-conventions#608"
data-hovercard-type="issue"
data-hovercard-url="/open-telemetry/semantic-conventions/issues/608/hovercard"
aria-keyshortcuts="Alt+ArrowUp">open-telemetry#608</a>, <a
href="open-telemetry/semantic-conventions#1708"
data-hovercard-type="pull_request"
data-hovercard-url="/open-telemetry/semantic-conventions/pull/1708/hovercard"
aria-keyshortcuts="Alt+ArrowUp">open-telemetry#1708</a>, <a
href="open-telemetry/semantic-conventions#1698"
data-hovercard-type="pull_request"
data-hovercard-url="/open-telemetry/semantic-conventions/pull/1698/hovercard"
aria-keyshortcuts="Alt+ArrowUp">open-telemetry#1698</a>)</p>
<ul>
<li>Renamed attributes:
<ul>
<li><code>az.service_request_id</code> to
<code>azure.service.request.id</code></li>
<li><code>az.namespace</code> to
<code>azure.resource_provider.namespace</code></li>
</ul>
</li>
<li>Renamed events:
<ul>
<li><code>az.resource.log</code> to <code>azure.resource.log</code></li>
</ul>
</li>
<li>Renamed enum members:
<ul>
<li><code>az.ai.inference</code> to <code>azure.ai.inference</code> (on
<code>gen_ai.system</code>)</li>
<li><code>az.ai.openai</code> to <code>azure.ai.openai</code> (on
<code>gen_ai.system</code>)</li>
<li><code>azure_aks</code> to <code>azure.aks</code> (on
<code>cloud.platform</code>)</li>
<li><code>azure_app_service</code> to <code>azure.app_service</code> (on
<code>cloud.platform</code>)</li>
<li><code>azure_container_apps</code> to
<code>azure.container_apps</code> (on <code>cloud.platform</code>)</li>
<li><code>azure_container_instances</code> to
<code>azure.container_instances</code> (on
<code>cloud.platform</code>)</li>
<li><code>azure_functions</code> to <code>azure.functions</code> (on
<code>cloud.platform</code>)</li>
<li><code>azure_openshift</code> to <code>azure.open_shift</code> (on
<code>cloud.platform</code>)</li>
<li><code>azure_vm</code> to <code>azure.vm</code> (on
<code>cloud.platform</code>)</li>
</ul>
</li>
</ul>
</li>
<li>
<p><code>system</code>: Revert the change that moved
<code>system.cpu.*</code> to <code>cpu.*</code>. The 3 affected metrics
are back in <code>system.cpu.*</code>. (<a
href="open-telemetry/semantic-conventions#1873"
data-hovercard-type="issue"
data-hovercard-url="/open-telemetry/semantic-conventions/issues/1873/hovercard"
aria-keyshortcuts="Alt+ArrowUp">open-telemetry#1873</a>)</p>
</li>
<li>
<p><code>system</code>: Changes system.network.connections to
system.network.connection.count (<a
href="open-telemetry/semantic-conventions#1800"
data-hovercard-type="issue"
data-hovercard-url="/open-telemetry/semantic-conventions/issues/1800/hovercard"
aria-keyshortcuts="Alt+ArrowUp">open-telemetry#1800</a>)</p>
</li>
<li>
<p><code>k8s</code>: Change instrument type for .limit/.request
container metrics from gauge to updowncounter (<a
href="open-telemetry/semantic-conventions#2354"
data-hovercard-type="pull_request"
data-hovercard-url="/open-telemetry/semantic-conventions/pull/2354/hovercard"
aria-keyshortcuts="Alt+ArrowUp">open-telemetry#2354</a>)</p>
</li>
</ul>
<h3>🚩 Deprecations 🚩</h3>
<ul>
<li><code>os</code>: Deprecate os.type='z_os' and replace with
os.type='zos' (<a
href="open-telemetry/semantic-conventions#1687"
data-hovercard-type="issue"
data-hovercard-url="/open-telemetry/semantic-conventions/issues/1687/hovercard"
aria-keyshortcuts="Alt+ArrowUp">open-telemetry#1687</a>)</li>
</ul>
<h3>🚀 New components 🚀</h3>
<ul>
<li><code>mainframe, zos</code>: Add initial semantic conventions for
mainframes (<a
href="open-telemetry/semantic-conventions#1687"
data-hovercard-type="issue"
data-hovercard-url="/open-telemetry/semantic-conventions/issues/1687/hovercard"
aria-keyshortcuts="Alt+ArrowUp">open-telemetry#1687</a>)</li>
</ul>
<h3>💡 Enhancements 💡</h3>
<ul>
<li>
<p><code>dotnet</code>: Define .NET-specific network spans for DNS
resolution, TLS handshake, and socket connections, along with HTTP-level
spans to (optionally) record relationships between HTTP requests and
connections.<br>
(<a
href="open-telemetry/semantic-conventions#1192"
data-hovercard-type="pull_request"
data-hovercard-url="/open-telemetry/semantic-conventions/pull/1192/hovercard"
aria-keyshortcuts="Alt+ArrowUp">open-telemetry#1192</a>)</p>
</li>
<li>
<p><code>k8s</code>: Add <code>k8s.node.allocatable.cpu</code>,
<code>k8s.node.allocatable.ephemeral_storage</code>,
<code>k8s.node.allocatable.memory</code>,
<code>k8s.node.allocatable.pods</code> metrics (<a
href="open-telemetry/semantic-conventions#2243"
data-hovercard-type="issue"
data-hovercard-url="/open-telemetry/semantic-conventions/issues/2243/hovercard"
aria-keyshortcuts="Alt+ArrowUp">open-telemetry#2243</a>)</p>
</li>
<li>
<p><code>k8s</code>: Add k8s.container.restart.count metric (<a
href="open-telemetry/semantic-conventions#2191"
data-hovercard-type="pull_request"
data-hovercard-url="/open-telemetry/semantic-conventions/pull/2191/hovercard"
aria-keyshortcuts="Alt+ArrowUp">open-telemetry#2191</a>)</p>
</li>
<li>
<p><code>k8s</code>: Add K8s container resource related metrics (<a
href="open-telemetry/semantic-conventions#2074"
data-hovercard-type="issue"
data-hovercard-url="/open-telemetry/semantic-conventions/issues/2074/hovercard"
aria-keyshortcuts="Alt+ArrowUp">open-telemetry#2074</a>)</p>
</li>
<li>
<p><code>k8s</code>: Add k8s.container.ready metric (<a
href="open-telemetry/semantic-conventions#2074"
data-hovercard-type="issue"
data-hovercard-url="/open-telemetry/semantic-conventions/issues/2074/hovercard"
aria-keyshortcuts="Alt+ArrowUp">open-telemetry#2074</a>)</p>
</li>
<li>
<p><code>k8s</code>: Add k8s.node.condition metric (<a
href="open-telemetry/semantic-conventions#2077"
data-hovercard-type="issue"
data-hovercard-url="/open-telemetry/semantic-conventions/issues/2077/hovercard"
aria-keyshortcuts="Alt+ArrowUp">open-telemetry#2077</a>)</p>
</li>
<li>
<p><code>k8s</code>: Add k8s resource quota metrics (<a
href="open-telemetry/semantic-conventions#2076"
data-hovercard-type="issue"
data-hovercard-url="/open-telemetry/semantic-conventions/issues/2076/hovercard"
aria-keyshortcuts="Alt+ArrowUp">open-telemetry#2076</a>)</p>
</li>
<li>
<p><code>events</code>: Update general event guidance to allow complex
attributes on events and use them instead of the body fields.<br>
(<a
href="open-telemetry/semantic-conventions#1651"
data-hovercard-type="issue"
data-hovercard-url="/open-telemetry/semantic-conventions/issues/1651/hovercard"
aria-keyshortcuts="Alt+ArrowUp">open-telemetry#1651</a>, <a
href="open-telemetry/semantic-conventions#1669"
data-hovercard-type="issue"
data-hovercard-url="/open-telemetry/semantic-conventions/issues/1669/hovercard"
aria-keyshortcuts="Alt+ArrowUp">open-telemetry#1669</a>)</p>
</li>
<li>
<p><code>k8s</code>: Add k8s.container.status.state and
k8s.container.status.reason metrics (<a
href="open-telemetry/semantic-conventions#1672"
data-hovercard-type="issue"
data-hovercard-url="/open-telemetry/semantic-conventions/issues/1672/hovercard"
aria-keyshortcuts="Alt+ArrowUp">open-telemetry#1672</a>)</p>
</li>
<li>
<p><code>feature_flags</code>: Mark feature flag semantic convention as
release candidate. (<a
href="open-telemetry/semantic-conventions#2277"
data-hovercard-type="pull_request"
data-hovercard-url="/open-telemetry/semantic-conventions/pull/2277/hovercard"
aria-keyshortcuts="Alt+ArrowUp">open-telemetry#2277</a>)</p>
</li>
<li>
<p><code>k8s</code>: Add new resource attributes for
<code>k8s.hpa</code> to capture the <code>scaleTargetRef</code> fields
(<a
href="open-telemetry/semantic-conventions#2008"
data-hovercard-type="issue"
data-hovercard-url="/open-telemetry/semantic-conventions/issues/2008/hovercard"
aria-keyshortcuts="Alt+ArrowUp">open-telemetry#2008</a>)<br>
Adds below attributes to the <code>k8s.hpa</code> resource:</p>
<ul>
<li><code>k8s.hpa.scaletargetref.kind</code></li>
<li><code>k8s.hpa.scaletargetref.name</code></li>
<li><code>k8s.hpa.scaletargetref.api_version</code></li>
</ul>
</li>
<li>
<p><code>k8s</code>: Adds metrics and attributes to track k8s HPA's
metric target values for CPU resources. (<a
href="open-telemetry/semantic-conventions#2182"
data-hovercard-type="issue"
data-hovercard-url="/open-telemetry/semantic-conventions/issues/2182/hovercard"
aria-keyshortcuts="Alt+ArrowUp">open-telemetry#2182</a>)<br>
Below metrics are introduced to provide insight into HPA scaling
configuration for CPU.</p>
<ul>
<li><code>k8s.hpa.metric.target.cpu.value</code></li>
<li><code>k8s.hpa.metric.target.cpu.average_value</code></li>
<li><code>k8s.hpa.metric.target.cpu.average_utilization</code></li>
</ul>
</li>
<li>
<p><code>k8s</code>: Explains the rationale behind the Kubernetes
resource naming convention. (<a
href="open-telemetry/semantic-conventions#2245"
data-hovercard-type="issue"
data-hovercard-url="/open-telemetry/semantic-conventions/issues/2245/hovercard"
aria-keyshortcuts="Alt+ArrowUp">open-telemetry#2245</a>)</p>
</li>
<li>
<p><code>all</code>: Adds modelling guide for resource and entity. (<a
href="open-telemetry/semantic-conventions#2246"
data-hovercard-type="issue"
data-hovercard-url="/open-telemetry/semantic-conventions/issues/2246/hovercard"
aria-keyshortcuts="Alt+ArrowUp">open-telemetry#2246</a>)</p>
</li>
<li>
<p><code>service</code>: Adds stability policies for Entity groups. (<a
href="open-telemetry/semantic-conventions#2378"
data-hovercard-type="pull_request"
data-hovercard-url="/open-telemetry/semantic-conventions/pull/2378/hovercard"
aria-keyshortcuts="Alt+ArrowUp">open-telemetry#2378</a>)<br>
Entity groups now require <code>role</code> to be filled for
attributes.</p>
</li>
<li>
<p><code>otel</code>: Specifies component.type values for Zipkin and
Prometheus exporters (<a
href="open-telemetry/semantic-conventions#2229"
data-hovercard-type="pull_request"
data-hovercard-url="/open-telemetry/semantic-conventions/pull/2229/hovercard"
aria-keyshortcuts="Alt+ArrowUp">open-telemetry#2229</a>)</p>
</li>
</ul>
<h3>🧰 Bug fixes 🧰</h3>
<ul>
<li><code>otel</code>: Removes <code>otel.scope</code> entity. (<a
href="open-telemetry/semantic-conventions#2310"
data-hovercard-type="pull_request"
data-hovercard-url="/open-telemetry/semantic-conventions/pull/2310/hovercard"
aria-keyshortcuts="Alt+ArrowUp">open-telemetry#2310</a>)</li>
</ul>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:propagators Part of OpenTelemetry context propagation enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Consider having a map and request header Carrier in SDK

5 participants