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>
221 lines
6.1 KiB
Django/Jinja
221 lines
6.1 KiB
Django/Jinja
{% import 'helpers.j2' as h -%}
|
|
|
|
{%- macro instrument_default(metric) -%}
|
|
{%- set ns = namespace(value="Int64", inst="unknown") -%}
|
|
{%- set divisible = ["s", "ms"] -%}
|
|
{%- if metric.unit is in divisible -%}
|
|
{%- set ns.value="Float64" -%}
|
|
{%- endif -%}
|
|
{%- if metric.instrument == "counter" -%}
|
|
{%- set ns.inst="Counter" -%}
|
|
{%- elif metric.instrument == "updowncounter" -%}
|
|
{%- set ns.inst="UpDownCounter" -%}
|
|
{%- elif metric.instrument == "gauge" -%}
|
|
{%- set ns.inst="Gauge" -%}
|
|
{%- elif metric.instrument == "histogram" -%}
|
|
{%- set ns.inst="Histogram" -%}
|
|
{%- endif -%}
|
|
{{ ns.value ~ ns.inst }}
|
|
{%- endmacro -%}
|
|
|
|
{%- macro instrument(metric) -%}
|
|
{{ metric.metric_name | map_text("instrument", instrument_default(metric)) }}
|
|
{%- endmacro -%}
|
|
|
|
{%- macro value_type(metric) -%}
|
|
{%- if instrument(metric)[:7] == "Float64" -%}
|
|
Float64
|
|
{%- else -%}
|
|
Int64
|
|
{%- endif -%}
|
|
{%- endmacro -%}
|
|
|
|
{%- macro param_name(raw="", pkg="") -%}
|
|
{%- set reserved = [
|
|
"type", "break", "default", "func", "interface", "select", "case", "defer",
|
|
"go", "map", "struct", "chan", "else", "goto", "const", "fallthrough", "if",
|
|
"range", "type", "continue", "for", "import", "return", "var",
|
|
]-%}
|
|
{%- set name = raw -%}
|
|
{%- if pkg != "" -%}
|
|
{%- set n = pkg | length -%}
|
|
{%- if pkg == name[:n] -%}
|
|
{%- set name = name[n:] -%}
|
|
{%- if name[0] == "." or name[0] == "." -%}
|
|
{%- set name = name[1:] -%}
|
|
{%- endif -%}
|
|
{%- endif -%}
|
|
{%- endif -%}
|
|
{%- if name | lower is in reserved -%}
|
|
{{ raw | camel_case }}
|
|
{%- else -%}
|
|
{{ name | camel_case }}
|
|
{%- endif -%}
|
|
{%- endmacro -%}
|
|
|
|
{%- macro params_docs(attrs, pkg="") -%}
|
|
{%- set ns = namespace(output='') -%}
|
|
{%- for attr in attrs | required | attribute_sort -%}
|
|
{%- set ns.output = ns.output ~ "\n\nThe " ~ param_name(attr.name, pkg) ~ " is the " ~ h.lower_first(attr.brief) -%}
|
|
{%- endfor -%}
|
|
{%- if attrs | not_required | length > 0 -%}
|
|
{%- set ns.output = ns.output ~ "\n\nAll additional attrs passed are included in the recorded value." -%}
|
|
{%- endif -%}
|
|
{%- if ns.output != "" -%}
|
|
//
|
|
{{ ns.output | comment }}
|
|
{%- endif -%}
|
|
{%- endmacro -%}
|
|
|
|
{%- macro param(attr, pkg="") -%}
|
|
{%- if attr.type is mapping -%}
|
|
{{ param_name(attr.name, pkg) }} {{ h.to_go_name(attr.name, pkg) }}Attr,
|
|
{%- else -%}
|
|
{{ param_name(attr.name, pkg) }} {{ attr.type | map_text("attribute_type_value")}},
|
|
{%- endif -%}
|
|
{%- endmacro -%}
|
|
|
|
{%- macro params(attrs, type="", pkg="", prefix="") -%}
|
|
{%- for attr in attrs | required | attribute_sort -%}
|
|
{{ prefix ~ param(attr, pkg) }}
|
|
{% endfor -%}
|
|
{{ prefix ~ "attrs ...attribute.KeyValue," }}
|
|
{%- endmacro -%}
|
|
|
|
{%- macro to_attribute(attr, pkg="") -%}
|
|
{%- if attr.type is mapping -%}
|
|
attribute.{{ h.attr_type(attr) | map_text("attribute_type_method")}}("{{ attr.name }}", {{ h.member_type(attr.type.members[0]) }}({{ param_name(attr.name, pkg) }})),
|
|
{%- else -%}
|
|
attribute.{{ attr.type | map_text("attribute_type_method")}}("{{ attr.name }}", {{ param_name(attr.name, pkg) }}),
|
|
{%- endif -%}
|
|
{%- endmacro -%}
|
|
|
|
{%- macro with_attributes_opt(attrs, pkg="", prefix="") -%}
|
|
{%- if attrs | length > 0 -%}
|
|
{{ prefix }}metric.WithAttributes(
|
|
{%- if attrs | required | length > 0 %}
|
|
{{ prefix }} append(
|
|
{{ prefix }} attrs,
|
|
{%- for attr in attrs | required | attribute_sort %}
|
|
{{ prefix }} {{ to_attribute(attr, pkg) }}
|
|
{%- endfor %}
|
|
{{ prefix }} )...,
|
|
{%- else %}
|
|
{{ prefix }} attrs...,
|
|
{%- endif %}
|
|
{{ prefix }}),
|
|
{%- endif -%}
|
|
{%- endmacro -%}
|
|
|
|
{%- macro add_method_with_optional(metric, inst, pkg="") -%}
|
|
{%- set name = h.to_go_name(metric.metric_name, pkg) -%}
|
|
{%- set req_attr = metric.attributes | required | attribute_sort -%}
|
|
func (m {{ name }}) Add(
|
|
ctx context.Context,
|
|
incr {{ value_type(metric) | lower }},
|
|
{{ params(metric.attributes, pkg=pkg, prefix="\t") }}
|
|
) {
|
|
o := addOptPool.Get().(*[]metric.AddOption)
|
|
defer func() {
|
|
*o = (*o)[:0]
|
|
addOptPool.Put(o)
|
|
}()
|
|
|
|
*o = append(
|
|
*o,
|
|
{{ with_attributes_opt(metric.attributes, pkg=pkg, prefix="\t\t") }}
|
|
)
|
|
|
|
m.{{ inst }}.Add(ctx, incr, *o...)
|
|
}
|
|
{%- endmacro -%}
|
|
|
|
{%- macro add_method(metric, inst, pkg="") -%}
|
|
|
|
// Add adds incr to the existing count.
|
|
{%- if metric.attributes | length > 0 %}
|
|
{{ params_docs(metric.attributes, pkg=pkg) }}
|
|
{%- if metric.note is defined %}
|
|
//
|
|
{{ metric.note | comment }}
|
|
{%- endif %}
|
|
{{ add_method_with_optional(metric, inst, pkg) }}
|
|
{%- else %}
|
|
{%- if metric.note is defined %}
|
|
//
|
|
{{ metric.note | comment }}
|
|
{%- endif %}
|
|
func (m {{ h.to_go_name(metric.metric_name, pkg) }}) Add(ctx context.Context, incr {{ value_type(metric) | lower }}, attrs ...attribute.KeyValue) {
|
|
if len(attrs) == 0 {
|
|
m.{{ inst }}.Add(ctx, incr)
|
|
return
|
|
}
|
|
|
|
o := addOptPool.Get().(*[]metric.AddOption)
|
|
defer func() {
|
|
*o = (*o)[:0]
|
|
addOptPool.Put(o)
|
|
}()
|
|
|
|
*o = append(*o, metric.WithAttributes(attrs...))
|
|
m.{{ inst }}.Add(ctx, incr, *o...)
|
|
}
|
|
{%- endif -%}
|
|
{%- endmacro -%}
|
|
|
|
{%- macro record_method_with_optional(metric, inst, pkg="") -%}
|
|
{%- set name = h.to_go_name(metric.metric_name, pkg) -%}
|
|
{%- set req_attr = metric.attributes | required | attribute_sort -%}
|
|
func (m {{ name }}) Record(
|
|
ctx context.Context,
|
|
val {{ value_type(metric) | lower }},
|
|
{{ params(metric.attributes, pkg=pkg, prefix="\t") }}
|
|
) {
|
|
o := recOptPool.Get().(*[]metric.RecordOption)
|
|
defer func() {
|
|
*o = (*o)[:0]
|
|
recOptPool.Put(o)
|
|
}()
|
|
|
|
*o = append(
|
|
*o,
|
|
{{ with_attributes_opt(metric.attributes, pkg=pkg, prefix="\t\t") }}
|
|
)
|
|
|
|
m.{{ inst }}.Record(ctx, val, *o...)
|
|
}
|
|
{%- endmacro -%}
|
|
|
|
{%- macro record_method(metric, inst, pkg="") -%}
|
|
|
|
// Record records val to the current distribution.
|
|
{%- if metric.attributes | length > 0 %}
|
|
{{ params_docs(metric.attributes, pkg=pkg) }}
|
|
{%- if metric.note is defined %}
|
|
//
|
|
{{ metric.note | comment }}
|
|
{%- endif %}
|
|
{{ record_method_with_optional(metric, inst, pkg) }}
|
|
{%- else %}
|
|
{%- set name = h.to_go_name(metric.metric_name, pkg) -%}
|
|
{%- if metric.note is defined %}
|
|
//
|
|
{{ metric.note | comment }}
|
|
{%- endif %}
|
|
func (m {{ name }}) Record(ctx context.Context, val {{ value_type(metric) | lower }}, attrs ...attribute.KeyValue) {
|
|
if len(attrs) == 0 {
|
|
m.{{ inst }}.Record(ctx, val)
|
|
}
|
|
|
|
o := recOptPool.Get().(*[]metric.RecordOption)
|
|
defer func() {
|
|
*o = (*o)[:0]
|
|
recOptPool.Put(o)
|
|
}()
|
|
|
|
*o = append(*o, metric.WithAttributes(attrs...))
|
|
m.{{ inst }}.Record(ctx, val, *o...)
|
|
}
|
|
{%- endif -%}
|
|
{%- endmacro -%}
|