You've already forked opentelemetry-go
mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-08-10 22:31:50 +02:00
- Add the new metric API package structure prototyped in https://github.com/MrAlias/semconv-go Prototypes of new metric API use: - https://github.com/MrAlias/opentelemetry-go-contrib/pull/6136 - https://github.com/MrAlias/opentelemetry-go-contrib/pull/6135 - https://github.com/MrAlias/opentelemetry-go-contrib/pull/6134 - Generate `semconv/v1.32.0` - Drop the `kestrel` metric namespace as this is a Java specific technology ## [`v1.32.0` semantic convention release notes](https://github.com/open-telemetry/semantic-conventions/releases/tag/v1.32.0): <div data-pjax="true" data-test-selector="body-content" data-view-component="true" class="markdown-body my-3"><p>📣 This release is the second release candidate for the Database Semantic Conventions, with <strong>db conventions stability planned to be declared in the subsequent release</strong>.</p> <h3>🛑 Breaking changes 🛑</h3> <ul> <li><code>device</code>: Change the definition of <code>device.id</code> and make it opt-in. (<a href="https://github.com/open-telemetry/semantic-conventions/issues/1874" data-hovercard-type="issue" data-hovercard-url="/open-telemetry/semantic-conventions/issues/1874/hovercard">#1874</a>, <a href="https://github.com/open-telemetry/semantic-conventions/issues/1951" data-hovercard-type="pull_request" data-hovercard-url="/open-telemetry/semantic-conventions/pull/1951/hovercard">#1951</a>)</li> <li><code>feature_flag</code>: Rename <code>evaluation</code> to <code>result</code> for feature flag evaluation result attributes (<a href="https://github.com/open-telemetry/semantic-conventions/issues/1989" data-hovercard-type="pull_request" data-hovercard-url="/open-telemetry/semantic-conventions/pull/1989/hovercard">#1989</a>)</li> </ul> <h3>🚀 New components 🚀</h3> <ul> <li><code>app</code>: Create <code>app.installation.id</code> attribute (<a href="https://github.com/open-telemetry/semantic-conventions/issues/1874" data-hovercard-type="issue" data-hovercard-url="/open-telemetry/semantic-conventions/issues/1874/hovercard">#1874</a>, <a href="https://github.com/open-telemetry/semantic-conventions/issues/1897" data-hovercard-type="pull_request" data-hovercard-url="/open-telemetry/semantic-conventions/pull/1897/hovercard">#1897</a>)</li> <li><code>cpython</code>: Add CPython runtime garbage collector metrics (<a href="https://github.com/open-telemetry/semantic-conventions/issues/1930" data-hovercard-type="issue" data-hovercard-url="/open-telemetry/semantic-conventions/issues/1930/hovercard">#1930</a>)</li> </ul> <h3>💡 Enhancements 💡</h3> <ul> <li><code>vcs</code>: Add owner and provider name to VCS attribute registry (<a href="https://github.com/open-telemetry/semantic-conventions/issues/1452" data-hovercard-type="issue" data-hovercard-url="/open-telemetry/semantic-conventions/issues/1452/hovercard">#1452</a>)</li> <li><code>vcs</code>: Remove fallback value for VCS provider name attribute (<a href="https://github.com/open-telemetry/semantic-conventions/issues/2020" data-hovercard-type="pull_request" data-hovercard-url="/open-telemetry/semantic-conventions/pull/2020/hovercard">#2020</a>)</li> <li><code>db</code>: Truncate <code>db.query.summary</code> to 255 characters if parsed from the query (<a href="https://github.com/open-telemetry/semantic-conventions/issues/1978" data-hovercard-type="issue" data-hovercard-url="/open-telemetry/semantic-conventions/issues/1978/hovercard">#1978</a>)</li> <li><code>db</code>: Normalize spaces in <code>db.operation.name</code> (if any) (<a href="https://github.com/open-telemetry/semantic-conventions/issues/2028" data-hovercard-type="issue" data-hovercard-url="/open-telemetry/semantic-conventions/issues/2028/hovercard">#2028</a>)</li> <li><code>db</code>: <code>db.operation.parameter.<key></code> should not be captured for batch operations (<a href="https://github.com/open-telemetry/semantic-conventions/issues/2026" data-hovercard-type="issue" data-hovercard-url="/open-telemetry/semantic-conventions/issues/2026/hovercard">#2026</a>)</li> <li><code>db</code>: Add <code>db.stored_procedure.name</code> (<a href="https://github.com/open-telemetry/semantic-conventions/issues/1491" data-hovercard-type="issue" data-hovercard-url="/open-telemetry/semantic-conventions/issues/1491/hovercard">#1491</a>)</li> <li><code>gcp</code>: Adds GCP AppHub labels for resource. (<a href="https://github.com/open-telemetry/semantic-conventions/issues/2006" data-hovercard-type="pull_request" data-hovercard-url="/open-telemetry/semantic-conventions/pull/2006/hovercard">#2006</a>)</li> <li><code>error</code>: Add <code>error.message</code> property for human-readable error message on events. (<a href="https://github.com/open-telemetry/semantic-conventions/issues/1992" data-hovercard-type="pull_request" data-hovercard-url="/open-telemetry/semantic-conventions/pull/1992/hovercard">#1992</a>)</li> <li><code>profile</code>: Extend the list of known frame types with a value for Go and Rust (<a href="https://github.com/open-telemetry/semantic-conventions/issues/2003" data-hovercard-type="pull_request" data-hovercard-url="/open-telemetry/semantic-conventions/pull/2003/hovercard">#2003</a>)</li> <li><code>otel</code>: Adds SDK self-monitoring metrics for log processing (<a href="https://github.com/open-telemetry/semantic-conventions/issues/1921" data-hovercard-type="pull_request" data-hovercard-url="/open-telemetry/semantic-conventions/pull/1921/hovercard">#1921</a>)</li> </ul>
117 lines
4.1 KiB
Django/Jinja
117 lines
4.1 KiB
Django/Jinja
{% import 'helpers.j2' as h -%}
|
|
{% import 'instrument.j2' as i -%}
|
|
// Code generated from semantic convention specification. DO NOT EDIT.
|
|
|
|
// Package httpconv provides types and functionality for OpenTelemetry semantic
|
|
// conventions in the "{{ ctx.root_namespace }}" namespace.
|
|
package {{ ctx.root_namespace | camel_case | lower }}conv
|
|
|
|
import (
|
|
"context"
|
|
"sync"
|
|
|
|
"go.opentelemetry.io/otel/attribute"
|
|
"go.opentelemetry.io/otel/metric"
|
|
"go.opentelemetry.io/otel/metric/noop"
|
|
)
|
|
|
|
var (
|
|
addOptPool = &sync.Pool{New: func() any { return &[]metric.AddOption{} }}
|
|
recOptPool = &sync.Pool{New: func() any { return &[]metric.RecordOption{} }}
|
|
)
|
|
{%- for attr in ctx.metrics | map(attribute="attributes") | flatten | selectattr("type", "mapping") | unique(attribute="name") | sort(attribute="name") %}
|
|
{%- set name = h.to_go_name(attr.name, ctx.root_namespace) %}
|
|
|
|
{{ [ name ~ "Attr is an attribute conforming to the " ~ attr.name ~ " semantic conventions. " ~ h.it_reps(attr.brief) ] | comment }}
|
|
type {{ name }}Attr {{ h.member_type(attr.type.members[0]) }}
|
|
|
|
var (
|
|
{%- for m in attr.type.members if not m.deprecated %}
|
|
{%- set m_name = name ~ h.to_go_name(m.id, ctx.root_namespace) %}
|
|
{{ h.prefix_brief(m.brief, m_name ~ " is ") | comment(format="go_1tab") }}
|
|
{{ m_name }} {{ name }}Attr = {% if attr.type.members[0].value is string -%}
|
|
"{{ m.value }}"
|
|
{%- else -%}
|
|
{{ m.value }}
|
|
{%- endif -%}
|
|
{%- endfor %}
|
|
)
|
|
{%- endfor %}
|
|
|
|
{%- for metric in ctx.metrics if not metric.deprecated %}
|
|
{%- set metric_name = h.to_go_name(metric.metric_name, ctx.root_namespace) %}
|
|
{%- set metric_inst = metric.metric_name | map_text("instrument", i.instrument_default(metric)) %}
|
|
|
|
{{ h.metric_typedoc(metric, ctx.root_namespace) | comment | trim }}
|
|
type {{ metric_name }} struct {
|
|
metric.{{ metric_inst }}
|
|
}
|
|
|
|
{{ ["New" ~ metric_name ~ " returns a new " ~ metric_name ~ " instrument."] | comment }}
|
|
func New{{ metric_name }}(
|
|
m metric.Meter,
|
|
opt ...metric.{{ metric_inst}}Option,
|
|
) ({{ metric_name }}, error) {
|
|
// Check if the meter is nil.
|
|
if m == nil {
|
|
return {{metric_name}}{noop.{{ metric_inst }}{}}, nil
|
|
}
|
|
|
|
i, err := m.{{ metric_inst }}(
|
|
"{{metric.metric_name}}",
|
|
append([]metric.{{ metric_inst }}Option{
|
|
metric.WithDescription("{{metric.brief | trim}}"),
|
|
metric.WithUnit("{{metric.unit}}"),
|
|
}, opt...)...,
|
|
)
|
|
if err != nil {
|
|
return {{metric_name}}{noop.{{ metric_inst }}{}}, err
|
|
}
|
|
return {{ metric_name }}{i}, nil
|
|
}
|
|
|
|
// Inst returns the underlying metric instrument.
|
|
func (m {{ metric_name }}) Inst() metric.{{ metric_inst }} {
|
|
return m.{{ metric_inst }}
|
|
}
|
|
|
|
// Name returns the semantic convention name of the instrument.
|
|
func ({{ metric_name }}) Name() string {
|
|
return "{{ metric.metric_name }}"
|
|
}
|
|
|
|
// Unit returns the semantic convention unit of the instrument
|
|
func ({{ metric_name }}) Unit() string {
|
|
return "{{ metric.unit }}"
|
|
}
|
|
{%- if metric.brief %}
|
|
|
|
// Description returns the semantic convention description of the instrument
|
|
func ({{ metric_name }}) Description() string {
|
|
return "{{ metric.brief | trim }}"
|
|
}
|
|
{%- endif %}
|
|
{%- if "Observable" is in metric_inst %}
|
|
{%- elif metric.instrument == "counter" or metric.instrument == "updowncounter" %}
|
|
|
|
{{ i.add_method(metric, metric_inst, ctx.root_namespace) }}
|
|
{%- elif metric.instrument == "histogram" or metric.instrument == "gauge" %}
|
|
|
|
{{ i.record_method(metric, metric_inst, ctx.root_namespace) }}
|
|
{%- endif %}
|
|
{%- for attr in metric.attributes | not_required | attribute_sort %}
|
|
{%- set name = h.to_go_name(attr.name, ctx.root_namespace) %}
|
|
|
|
{{ [ "Attr" ~ name ~ " returns an optional attribute for the \"" ~ attr.name ~ "\" semantic convention. " ~ h.it_reps(attr.brief) ] | comment }}
|
|
{%- if attr.type is mapping %}
|
|
func ({{ metric_name}}) Attr{{name}}(val {{ name }}Attr) attribute.KeyValue {
|
|
return attribute.{{ h.attr_type(attr) | map_text("attribute_type_method")}}("{{ attr.name }}", {{ h.member_type(attr.type.members[0]) }}(val))
|
|
}
|
|
{%- else %}
|
|
func ({{ metric_name}}) Attr{{name}}(val {{ attr.type | map_text("attribute_type_value")}}) attribute.KeyValue {
|
|
return attribute.{{ h.attr_type(attr) | map_text("attribute_type_method")}}("{{ attr.name }}", val)
|
|
}
|
|
{%- endif %}
|
|
{%- endfor %}
|
|
{%- endfor %}
|