From 1e5366e0172f3c293cb1a3d26f008a90b42c5285 Mon Sep 17 00:00:00 2001 From: Yordis Prieto Date: Tue, 13 Oct 2026 13:25:19 -0400 Subject: [PATCH 1/2] fix(go): align generated names with the official semantic conventions packages Signed-off-by: Yordis Prieto --- templates/code/go/README.md | 84 +-- templates/code/go/attributes.go.j2 | 2 +- templates/code/go/entities.go.j2 | 4 +- templates/code/go/events.go.j2 | 2 +- templates/code/go/metrics.go.j2 | 68 ++- templates/code/go/spans.go.j2 | 4 +- .../expected/authattr/attributes.go | 38 +- .../expected/myappattr/attributes.go | 190 +++---- .../entities/expected/myappattr/attributes.go | 82 +-- .../entities/expected/myappentity/entities.go | 108 ++-- .../expected-error.txt | 1 + .../registry/manifest.yaml | 2 + .../registry/myapp.yaml | 17 + .../expected-error.txt | 1 + .../registry/manifest.yaml | 2 + .../registry/myapp.yaml | 30 ++ .../expected-error.txt | 1 + .../registry/manifest.yaml | 2 + .../registry/model.yaml | 27 + .../expected-error.txt | 1 + .../registry/manifest.yaml | 2 + .../registry/myapp.yaml | 16 + .../events/expected/myappattr/attributes.go | 26 +- .../events/expected/myappevent/events.go | 12 +- .../events/expected/workerattr/attributes.go | 14 +- .../events/expected/workerevent/events.go | 6 +- .../expected/myappattr/attributes.go | 14 +- .../expected/myappmetric/metrics.go | 184 +++++-- .../expected/myappattr/attributes.go | 14 +- .../expected/myappmetric/metrics.go | 91 +++- .../imported/expected/edgemetric/metrics.go | 67 ++- .../tests/imported/expected/edgespan/spans.go | 30 +- .../imported/expected/myappattr/attributes.go | 14 +- .../imported/expected/myappmetric/metrics.go | 135 +++-- .../expected/myappattr/attributes.go | 14 +- .../expected/myappevent/events.go | 2 +- .../expected/myappmetric/metrics.go | 134 +++-- .../expected/myappspan/spans.go | 26 +- .../metrics/expected/authattr/attributes.go | 26 +- .../metrics/expected/authmetric/metrics.go | 109 ++-- .../metrics/expected/myappattr/attributes.go | 26 +- .../metrics/expected/myappmetric/metrics.go | 503 ++++++++++++------ .../metrics/expected/workermetric/metrics.go | 77 ++- .../expected/exceptionattr/attributes.go | 28 +- .../expected/exceptionevent/events.go | 6 +- .../expected/heartbeatattr/attributes.go | 28 +- .../expected/heartbeatspan/spans.go | 6 +- .../expected/hostattr/attributes.go | 28 +- .../expected/hostentity/entities.go | 6 +- .../params/expected/billingattr/attributes.go | 28 +- .../params/expected/billingmetric/metrics.go | 78 ++- .../params/expected/myappattr/attributes.go | 14 +- .../expected/myappattr/attributes.go | 14 +- .../expected/myappmetric/metrics.go | 112 ++-- .../expected/myappattr/attributes.go | 14 +- .../expected/myappmetric/metrics.go | 112 ++-- .../spans/expected/myappattr/attributes.go | 54 +- .../tests/spans/expected/myappspan/spans.go | 95 ++-- .../spans/expected/workerattr/attributes.go | 28 +- .../tests/spans/expected/workerspan/spans.go | 36 +- templates/code/go/weaver.yaml | 29 +- 61 files changed, 1826 insertions(+), 1098 deletions(-) create mode 100644 templates/code/go/tests/error_attribute_member_collision/expected-error.txt create mode 100644 templates/code/go/tests/error_attribute_member_collision/registry/manifest.yaml create mode 100644 templates/code/go/tests/error_attribute_member_collision/registry/myapp.yaml create mode 100644 templates/code/go/tests/error_entity_attr_collision/expected-error.txt create mode 100644 templates/code/go/tests/error_entity_attr_collision/registry/manifest.yaml create mode 100644 templates/code/go/tests/error_entity_attr_collision/registry/myapp.yaml create mode 100644 templates/code/go/tests/error_metric_attr_collision/expected-error.txt create mode 100644 templates/code/go/tests/error_metric_attr_collision/registry/manifest.yaml create mode 100644 templates/code/go/tests/error_metric_attr_collision/registry/model.yaml create mode 100644 templates/code/go/tests/error_span_name_collision/expected-error.txt create mode 100644 templates/code/go/tests/error_span_name_collision/registry/manifest.yaml create mode 100644 templates/code/go/tests/error_span_name_collision/registry/myapp.yaml diff --git a/templates/code/go/README.md b/templates/code/go/README.md index 1082a98..aba168b 100644 --- a/templates/code/go/README.md +++ b/templates/code/go/README.md @@ -55,7 +55,7 @@ that carries the registry's schema URL: The namespace is the first segment of a name, or the second when the first is listed in `vendor_prefixes`. Identifiers drop that prefix, so `myapp.task.id` -becomes `myappattr.TaskIDAttr`. +becomes `myappattr.TaskID`. ### Attributes @@ -63,9 +63,9 @@ Each attribute becomes a struct that can only be built through its constructor or, for enums, through its members: ```go -myappattr.NewTaskIDAttr("task_0001").KeyValue() +myappattr.NewTaskID("task_0001").KeyValue() myappattr.TaskStateQueued.KeyValue() -myappattr.TaskIDAttr{}.Key() +myappattr.TaskID{}.Key() ``` Supported types are `string`, `int`, `double`, `boolean`, their array forms, and @@ -139,35 +139,49 @@ The zero `Logger` emits log records that go nowhere. ### Metrics Each metric becomes a struct wrapping the matching synchronous instrument, built -with `New(meter)`. Required attributes are typed parameters of +with `New(meter)`. Required attributes are typed parameters of `Add` or `Record`, and every other attribute is a trailing option: ```go -duration, err := myappmetric.NewTaskDurationHistogram(meter) -duration.Record(ctx, 1.5, myappattr.NewTaskIDAttr("task_0001"), - myappmetric.WithTaskDurationHistogramTaskState(myappattr.TaskStateRunning)) +duration, err := myappmetric.NewTaskDuration(meter) +duration.Record(ctx, 1.5, myappattr.NewTaskID("task_0001"), + myappmetric.WithTaskDurationTaskState(myappattr.TaskStateRunning)) ``` Counters, up-down counters, and gauges also get an asynchronous form, built -with `NewObservable(meter, callback)`. The callback receives a +with `NewObservable(meter, callback)`. The callback receives a typed observer whose `Observe` takes the same parameters and options as the synchronous method, so an observation cannot skip a required attribute or attach one the convention does not declare: ```go -_, err := myappmetric.NewTaskActiveObservableUpDownCounter(meter, - func(ctx context.Context, o myappmetric.TaskActiveUpDownCounterObserver) error { +_, err := myappmetric.NewTaskActiveObservable(meter, + func(ctx context.Context, o myappmetric.TaskActiveObserver) error { o.Observe(int64(queue.Len()), myappattr.TaskStateQueued) return nil }) ``` -The callback has its own type, `Callback`, so it can be +The callback has its own type, `Callback`, so it can be declared ahead of the constructor. It is registered when the instrument is created and runs on every collection. An error it returns is returned by that collection, and the observations made before it are still recorded. Histograms have no asynchronous form in OpenTelemetry, so they get none. +Like the official `semconv` packages, each instrument type, synchronous or +observable, reports its registry metadata through `Name`, `Unit`, and +`Description`, which work on the zero value, and exposes the underlying +OpenTelemetry instrument through `Inst`: + +```go +myappmetric.TaskDuration{}.Name() // "myapp.task.duration" +duration.Inst() // metric.Float64Histogram +``` + +`Unit` and `Description` return an empty string when the registry sets none. +A refinement reports the name of the metric it refines, since both record into +one instrument. + Go cannot check a requirement condition, so conditionally required, recommended, and opt-in attributes are all options. The option's doc comment carries the level and its condition, such as @@ -185,7 +199,7 @@ plain Go value instead, with the key filled in, so an imported enum is taken as the Go value of its members: ```go -failed.Add(ctx, 1, "timeout", myappattr.NewTaskIDAttr("task_0001")) +failed.Add(ctx, 1, "timeout", myappattr.NewTaskID("task_0001")) ``` Map its namespace to the Go import path of a dependency registry that was @@ -194,7 +208,7 @@ attribute is taken as the typed value from `/attr` instead, exactly like a local attribute: ```go -failed.Add(ctx, 1, errorattr.TypeTimeout, myappattr.NewTaskIDAttr("task_0001")) +failed.Add(ctx, 1, errorattr.TypeTimeout, myappattr.NewTaskID("task_0001")) ``` The map's key is the attribute's namespace as this registry's own @@ -260,8 +274,8 @@ with the attributes and requirement levels the refinement declares. A refinement that makes an attribute required therefore makes it a parameter: ```go -retried, err := myappmetric.NewTaskRetryDurationHistogram(meter) -retried.Record(ctx, 1.5, myappattr.NewTaskIDAttr("task_0001"), myappattr.TaskStateDone) +retried, err := myappmetric.NewTaskRetryDuration(meter) +retried.Record(ctx, 1.5, myappattr.NewTaskID("task_0001"), myappattr.TaskStateDone) ``` It records under the name of the metric it refines, created with that metric's @@ -271,27 +285,27 @@ is generated only when the metric it refines is. ### Spans -Each span becomes a `Start` function and a `Span` it returns. The +Each span becomes a `Start` function and a `` it returns. The starter takes the `tracer.Tracer`, then every required attribute as a typed parameter, then the rest as options, and starts the span with the kind the registry gives it: ```go ctx, span := myappspan.StartTaskDispatch(ctx, tracer, - workerattr.NewHostNameAttr("worker-1"), - workerattr.NewHostPortAttr(8080), - myappspan.WithTaskDispatchTaskID(myappattr.NewTaskIDAttr("task_0001")), + workerattr.NewHostName("worker-1"), + workerattr.NewHostPort(8080), + myappspan.WithTaskDispatchTaskID(myappattr.NewTaskID("task_0001")), ) defer span.End() -span.SetAttributes(myappspan.WithTaskDispatchQueueName(myappattr.NewQueueNameAttr("reports"))) +span.SetAttributes(myappspan.WithTaskDispatchQueueName(myappattr.NewQueueName("reports"))) ``` Every attribute given to the starter is set as the span starts, since a sampler sees only those. An option for an attribute marked `sampling_relevant` returns only `StartAttr`, which the starter accepts, while every other option returns `Attr`, which `SetAttributes` also accepts after the span started. -`Span` also has `End`, `RecordError`, `SetStatus`, and `Span` for the -underlying `trace.Span`. The zero `Span` records nothing. +`` also has `End`, `RecordError`, `SetStatus`, and `Span` for the +underlying `trace.Span`. The zero `` records nothing. The span name comes from `name.note`, read only for a name template: a single code span holding at least one `{placeholder}`, each the key of an attribute @@ -318,7 +332,7 @@ has nothing left after its namespace. Rather than failing, it renders unprefixed, in its own `span` package: ```go -ctx, span := heartbeatspan.Start(ctx, tracer, heartbeatattr.NewSequenceAttr(1)) +ctx, span := heartbeatspan.Start(ctx, tracer, heartbeatattr.NewSequence(1)) defer span.End() ``` @@ -331,7 +345,7 @@ severity and the timestamp: ```go myappevent.EmitTaskFinished(ctx, logger, myappattr.TaskStateDone, - myappevent.WithTaskFinishedTaskAttempt(myappattr.NewTaskAttemptAttr(2)), + myappevent.WithTaskFinishedTaskAttempt(myappattr.NewTaskAttempt(2)), myappevent.WithTaskFinishedSeverity(log.SeverityWarn), ) ``` @@ -351,21 +365,21 @@ event, has nothing left after its namespace. Rather than failing, it renders unprefixed, in its own `event` package: ```go -exceptionevent.Emit(ctx, logger, exceptionattr.NewTypeAttr("ValueError"), - exceptionevent.WithMessage(exceptionattr.NewMessageAttr("division by zero")), +exceptionevent.Emit(ctx, logger, exceptionattr.NewType("ValueError"), + exceptionevent.WithMessage(exceptionattr.NewMessage("division by zero")), ) ``` ### Entities -Each entity becomes a `Entity` value type built by `NewEntity`. +Each entity becomes a `` value type built by `New`. A required attribute of the entity's identity or description is a typed parameter of the constructor, and every other attribute is a trailing option: ```go -host := myappentity.NewHostEntity( - myappattr.NewHostNameAttr("worker-1"), - myappentity.WithHostEntityHostType(myappattr.HostTypeVirtual), +host := myappentity.NewHost( + myappattr.NewHostName("worker-1"), + myappentity.WithHostHostType(myappattr.HostTypeVirtual), ) ``` @@ -377,7 +391,7 @@ schema. Resources from the same registry merge cleanly: res, err := resource.Merge(host.Resource(), queue.Resource()) ``` -The zero `Entity` carries no attributes. Identity attributes come +The zero `` carries no attributes. Identity attributes come before description attributes in both the constructor and the doc comment, so a reader can tell at a glance which attributes identify the entity and which merely describe it. @@ -393,7 +407,7 @@ after its namespace. Rather than failing, it renders unprefixed, in its own `entity` package: ```go -host := hostentity.NewEntity(hostattr.NewIDAttr("h-1")) +host := hostentity.NewEntity(hostattr.NewID("h-1")) ``` ### Deprecation @@ -480,9 +494,9 @@ that same `Resource`. Pass its attributes to `resource.New` under the registry's schema URL: ```go -host := myappentity.NewHostEntity( - myappattr.NewHostNameAttr(hostname), - myappentity.WithHostEntityHostType(myappattr.HostTypeVirtual), +host := myappentity.NewHost( + myappattr.NewHostName(hostname), + myappentity.WithHostHostType(myappattr.HostTypeVirtual), ) res, err := resource.New(ctx, diff --git a/templates/code/go/attributes.go.j2 b/templates/code/go/attributes.go.j2 index 0904ed1..80ca17a 100644 --- a/templates/code/go/attributes.go.j2 +++ b/templates/code/go/attributes.go.j2 @@ -9,7 +9,7 @@ package {{ ctx.namespace }}attr import "go.opentelemetry.io/otel/attribute" {% for attr in ctx.attributes -%} {%- set base = n.exported(attr.short_name) -%} -{%- set name = base ~ "Attr" -%} +{%- set name = base -%} {%- set key = n.unexported(attr.short_name) ~ "Key" -%} {%- set is_enum = attr.type is mapping -%} {%- set deprecated = d.notice(attr) %} diff --git a/templates/code/go/entities.go.j2 b/templates/code/go/entities.go.j2 index fa3c21b..deab650 100644 --- a/templates/code/go/entities.go.j2 +++ b/templates/code/go/entities.go.j2 @@ -5,7 +5,7 @@ {%- if a.imported -%} {{ a.attr_type | map_text("attribute_field_type") }} {%- else -%} -{{ a.attr_namespace }}attr.{{ n.exported(a.attr_short_name) }}Attr +{{ a.attr_namespace }}attr.{{ n.exported(a.attr_short_name) }} {%- endif -%} {%- endmacro -%} {%- macro attr_kv(a, v) -%} @@ -34,7 +34,7 @@ import ( {% for def in ctx.entities %} {%- set name = n.exported(def.short_name) %} {%- set private = n.unexported(def.short_name) if def.short_name else "bare" %} -{%- set entity = name ~ "Entity" %} +{%- set entity = name or "Entity" %} {%- set deprecated = d.notice(def) %} {%- set opt_in = "Opt-in: the convention records `" ~ def.id ~ "` only when a user asks for it." if def.requirement_level == "opt_in" else none -%} {% if def.optional %} diff --git a/templates/code/go/events.go.j2 b/templates/code/go/events.go.j2 index 6d380f2..e0553d0 100644 --- a/templates/code/go/events.go.j2 +++ b/templates/code/go/events.go.j2 @@ -5,7 +5,7 @@ {%- if a.imported -%} {{ a.attr_type | map_text("attribute_field_type") }} {%- else -%} -{{ a.attr_namespace }}attr.{{ n.exported(a.attr_short_name) }}Attr +{{ a.attr_namespace }}attr.{{ n.exported(a.attr_short_name) }} {%- endif -%} {%- endmacro -%} {%- macro attr_kv(a, v) -%} diff --git a/templates/code/go/metrics.go.j2 b/templates/code/go/metrics.go.j2 index c6d1b17..9f53fa4 100644 --- a/templates/code/go/metrics.go.j2 +++ b/templates/code/go/metrics.go.j2 @@ -5,7 +5,7 @@ {%- if a.imported -%} {{ a.attr_type | map_text("attribute_field_type") }} {%- else -%} -{{ a.attr_namespace }}attr.{{ n.exported(a.attr_short_name) }}Attr +{{ a.attr_namespace }}attr.{{ n.exported(a.attr_short_name) }} {%- endif -%} {%- endmacro -%} {%- macro attr_kv(a, v) -%} @@ -33,8 +33,8 @@ import ( ) {% for def in ctx.metrics %} {%- set suffix = def.instrument | map_text("metric_instrument") %} -{%- set name = n.exported(def.short_name) ~ suffix %} -{%- set private = n.unexported(def.short_name) ~ suffix %} +{%- set name = n.exported(def.short_name) %} +{%- set private = n.unexported(def.short_name) %} {%- set method = def.instrument | map_text("metric_instrument_method") %} {%- set arg = def.instrument | map_text("metric_instrument_arg") %} {%- set value_type = def.annotations.code_generation.metric_value_type | map_text("metric_value_type") %} @@ -66,20 +66,41 @@ type {{ name }} struct{ inst metric.{{ instrument }} } {{ ["New" ~ name ~ " creates the `" ~ def.instrument_name ~ "` instrument from meter.", opt_in, deprecated] | select | join("\n\n") | comment }} func New{{ name }}(meter {{ n.root() }}meter.Meter) ({{ name }}, error) { + var m {{ name }} inst, err := meter.MetricMeter().{{ instrument }}( - "{{ def.instrument_name }}", - metric.WithDescription({{ def.description | trim | tojson }}), - metric.WithUnit({{ def.unit | tojson }}), + m.Name(), + metric.WithDescription(m.Description()), + metric.WithUnit(m.Unit()), {%- if def.bucket_boundaries %} metric.WithExplicitBucketBoundaries({{ def.bucket_boundaries | join(", ") }}), {%- endif %} ) if err != nil { - return {{ name }}{}, fmt.Errorf("create the %s instrument: %w", "{{ def.instrument_name }}", err) + return {{ name }}{}, fmt.Errorf("create the %s instrument: %w", m.Name(), err) } return {{ name }}{inst: inst}, nil } +{{ ["Name returns the name `" ~ def.name ~ "` records under."] | join | comment }} +func ({{ name }}) Name() string { + return {{ def.instrument_name | tojson }} +} + +{{ ["Unit returns the unit of `" ~ def.name ~ "`."] | join | comment }} +func ({{ name }}) Unit() string { + return {{ (def.unit or "") | tojson }} +} + +{{ ["Description returns the description of `" ~ def.name ~ "`."] | join | comment }} +func ({{ name }}) Description() string { + return {{ (def.description or "") | trim | tojson }} +} + +{{ ["Inst returns the underlying metric." ~ instrument ~ ", or nil for the zero " ~ name ~ "."] | join | comment }} +func (m {{ name }}) Inst() metric.{{ instrument }} { + return m.inst +} + {{ [method ~ " records one `" ~ def.name ~ "` measurement. The zero " ~ name ~ " records nothing."] | join | comment }} func (m {{ name }}) {{ method }}(ctx context.Context, {{ arg }} {{ gotype }}{% for req in def.required %}, {{ n.unexported(req.attr_param) }} {{ attr_type(req) }}{% endfor %}{% if def.optional %}, opts ...{{ name }}Attr{% endif %}) { if m.inst == nil { @@ -101,7 +122,7 @@ func (m {{ name }}) {{ method }}(ctx context.Context, {{ arg }} {{ gotype }}{% f {%- endif %} } {%- if def.instrument != "histogram" %} -{%- set observable = n.exported(def.short_name) ~ "Observable" ~ suffix %} +{%- set observable = name ~ "Observable" %} {%- set observer = name ~ "Observer" %} {%- set callback = name ~ "Callback" %} @@ -141,21 +162,42 @@ type {{ observable }} struct { {{ ["New" ~ observable ~ " creates the `" ~ def.instrument_name ~ "` instrument from meter and registers callback to observe it on every collection.", opt_in, deprecated] | select | join("\n\n") | comment }} func New{{ observable }}(meter {{ n.root() }}meter.Meter, callback {{ callback }}) ({{ observable }}, error) { + var m {{ observable }} if callback == nil { - return {{ observable }}{}, fmt.Errorf("create the %s instrument: the callback is nil", "{{ def.instrument_name }}") + return {{ observable }}{}, fmt.Errorf("create the %s instrument: the callback is nil", m.Name()) } inst, err := meter.MetricMeter().{{ value_type }}Observable{{ suffix }}( - "{{ def.instrument_name }}", - metric.WithDescription({{ def.description | trim | tojson }}), - metric.WithUnit({{ def.unit | tojson }}), + m.Name(), + metric.WithDescription(m.Description()), + metric.WithUnit(m.Unit()), metric.With{{ value_type }}Callback(func(ctx context.Context, o metric.{{ value_type }}Observer) error { return callback(ctx, {{ observer }}{o: o}) }), ) if err != nil { - return {{ observable }}{}, fmt.Errorf("create the %s instrument: %w", "{{ def.instrument_name }}", err) + return {{ observable }}{}, fmt.Errorf("create the %s instrument: %w", m.Name(), err) } return {{ observable }}{inst: inst}, nil } + +{{ ["Name returns the name `" ~ def.name ~ "` records under."] | join | comment }} +func ({{ observable }}) Name() string { + return {{ name }}{}.Name() +} + +{{ ["Unit returns the unit of `" ~ def.name ~ "`."] | join | comment }} +func ({{ observable }}) Unit() string { + return {{ name }}{}.Unit() +} + +{{ ["Description returns the description of `" ~ def.name ~ "`."] | join | comment }} +func ({{ observable }}) Description() string { + return {{ name }}{}.Description() +} + +{{ ["Inst returns the underlying metric." ~ value_type ~ "Observable" ~ suffix ~ ", or nil for the zero " ~ observable ~ "."] | join | comment }} +func (m {{ observable }}) Inst() metric.{{ value_type }}Observable{{ suffix }} { + return m.inst +} {%- endif %} {% endfor %}{% endfilter %} diff --git a/templates/code/go/spans.go.j2 b/templates/code/go/spans.go.j2 index 5ce8d51..b10fe35 100644 --- a/templates/code/go/spans.go.j2 +++ b/templates/code/go/spans.go.j2 @@ -5,7 +5,7 @@ {%- if a.imported -%} {{ a.attr_type | map_text("attribute_field_type") }} {%- else -%} -{{ a.attr_namespace }}attr.{{ n.exported(a.attr_short_name) }}Attr +{{ a.attr_namespace }}attr.{{ n.exported(a.attr_short_name) }} {%- endif -%} {%- endmacro -%} {%- macro attr_kv(a, v) -%} @@ -35,7 +35,7 @@ import ( {% for def in ctx.spans %} {%- set name = n.exported(def.short_name) %} {%- set private = n.unexported(def.short_name) if def.short_name else "bare" %} -{%- set span = name ~ "Span" %} +{%- set span = name or "Span" %} {%- set start = "Start" ~ name %} {%- set deprecated = d.notice(def) %} {%- set opt_in = "Opt-in: the convention records `" ~ def.id ~ "` only when a user asks for it." if def.requirement_level == "opt_in" else none -%} diff --git a/templates/code/go/tests/attributes/expected/authattr/attributes.go b/templates/code/go/tests/attributes/expected/authattr/attributes.go index a88647b..9a9866b 100644 --- a/templates/code/go/tests/attributes/expected/authattr/attributes.go +++ b/templates/code/go/tests/attributes/expected/authattr/attributes.go @@ -7,18 +7,18 @@ import "go.opentelemetry.io/otel/attribute" // levelKey is the attribute key of `auth.level`. const levelKey = attribute.Key("auth.level") -// LevelAttr is a value of `auth.level`. +// Level is a value of `auth.level`. // // Assurance level of the authentication. -type LevelAttr struct{ value int } +type Level struct{ value int } // Key is the attribute key, for filters and views that need it. -func (LevelAttr) Key() attribute.Key { +func (Level) Key() attribute.Key { return levelKey } // KeyValue is the `auth.level` attribute set to this value. -func (v LevelAttr) KeyValue() attribute.KeyValue { +func (v Level) KeyValue() attribute.KeyValue { return levelKey.Int(v.value) } @@ -26,29 +26,29 @@ var ( // LevelLow is the 1 member of `auth.level`. // // Single factor. - LevelLow = LevelAttr{value: 1} + LevelLow = Level{value: 1} // LevelHigh is the 2 member of `auth.level`. // // Multiple factors. - LevelHigh = LevelAttr{value: 2} + LevelHigh = Level{value: 2} ) // methodKey is the attribute key of `auth.method`. const methodKey = attribute.Key("auth.method") -// MethodAttr is a value of `auth.method`. +// Method is a value of `auth.method`. // // How the user was authenticated. -type MethodAttr struct{ value string } +type Method struct{ value string } // Key is the attribute key, for filters and views that need it. -func (MethodAttr) Key() attribute.Key { +func (Method) Key() attribute.Key { return methodKey } // KeyValue is the `auth.method` attribute set to this value. -func (v MethodAttr) KeyValue() attribute.KeyValue { +func (v Method) KeyValue() attribute.KeyValue { return methodKey.String(v.value) } @@ -56,33 +56,33 @@ var ( // MethodPassword is the "password" member of `auth.method`. // // A password was checked. - MethodPassword = MethodAttr{value: "password"} + MethodPassword = Method{value: "password"} // MethodToken is the "token" member of `auth.method`. // // A bearer token was checked. - MethodToken = MethodAttr{value: "token"} + MethodToken = Method{value: "token"} ) // userIDKey is the attribute key of `auth.user.id`. const userIDKey = attribute.Key("auth.user.id") -// UserIDAttr is a value of `auth.user.id`. +// UserID is a value of `auth.user.id`. // // Identifier of the authenticated user. -type UserIDAttr struct{ value string } +type UserID struct{ value string } -// NewUserIDAttr returns a value of `auth.user.id`. -func NewUserIDAttr(value string) UserIDAttr { - return UserIDAttr{value: value} +// NewUserID returns a value of `auth.user.id`. +func NewUserID(value string) UserID { + return UserID{value: value} } // Key is the attribute key, for filters and views that need it. -func (UserIDAttr) Key() attribute.Key { +func (UserID) Key() attribute.Key { return userIDKey } // KeyValue is the `auth.user.id` attribute set to this value. -func (v UserIDAttr) KeyValue() attribute.KeyValue { +func (v UserID) KeyValue() attribute.KeyValue { return userIDKey.String(v.value) } diff --git a/templates/code/go/tests/attributes/expected/myappattr/attributes.go b/templates/code/go/tests/attributes/expected/myappattr/attributes.go index bb32d53..37043d0 100644 --- a/templates/code/go/tests/attributes/expected/myappattr/attributes.go +++ b/templates/code/go/tests/attributes/expected/myappattr/attributes.go @@ -7,98 +7,98 @@ import "go.opentelemetry.io/otel/attribute" // taskAssignedByKey is the attribute key of `myapp.task.assigned_by`. const taskAssignedByKey = attribute.Key("myapp.task.assigned_by") -// TaskAssignedByAttr is a value of `myapp.task.assigned_by`. +// TaskAssignedBy is a value of `myapp.task.assigned_by`. // // Who assigned the task. // // The scheduler sets it on every task it passes along to `myapp.task.state`. // Workers never set it themselves. -type TaskAssignedByAttr struct{ value string } +type TaskAssignedBy struct{ value string } -// NewTaskAssignedByAttr returns a value of `myapp.task.assigned_by`. -func NewTaskAssignedByAttr(value string) TaskAssignedByAttr { - return TaskAssignedByAttr{value: value} +// NewTaskAssignedBy returns a value of `myapp.task.assigned_by`. +func NewTaskAssignedBy(value string) TaskAssignedBy { + return TaskAssignedBy{value: value} } // Key is the attribute key, for filters and views that need it. -func (TaskAssignedByAttr) Key() attribute.Key { +func (TaskAssignedBy) Key() attribute.Key { return taskAssignedByKey } // KeyValue is the `myapp.task.assigned_by` attribute set to this value. -func (v TaskAssignedByAttr) KeyValue() attribute.KeyValue { +func (v TaskAssignedBy) KeyValue() attribute.KeyValue { return taskAssignedByKey.String(v.value) } // taskCancelledKey is the attribute key of `myapp.task.cancelled`. const taskCancelledKey = attribute.Key("myapp.task.cancelled") -// TaskCancelledAttr is a value of `myapp.task.cancelled`. +// TaskCancelled is a value of `myapp.task.cancelled`. // // Whether the task was cancelled. -type TaskCancelledAttr struct{ value bool } +type TaskCancelled struct{ value bool } -// NewTaskCancelledAttr returns a value of `myapp.task.cancelled`. -func NewTaskCancelledAttr(value bool) TaskCancelledAttr { - return TaskCancelledAttr{value: value} +// NewTaskCancelled returns a value of `myapp.task.cancelled`. +func NewTaskCancelled(value bool) TaskCancelled { + return TaskCancelled{value: value} } // Key is the attribute key, for filters and views that need it. -func (TaskCancelledAttr) Key() attribute.Key { +func (TaskCancelled) Key() attribute.Key { return taskCancelledKey } // KeyValue is the `myapp.task.cancelled` attribute set to this value. -func (v TaskCancelledAttr) KeyValue() attribute.KeyValue { +func (v TaskCancelled) KeyValue() attribute.KeyValue { return taskCancelledKey.Bool(v.value) } // taskFlagsKey is the attribute key of `myapp.task.flags`. const taskFlagsKey = attribute.Key("myapp.task.flags") -// TaskFlagsAttr is a value of `myapp.task.flags`. +// TaskFlags is a value of `myapp.task.flags`. // // Feature flags evaluated for the task. -type TaskFlagsAttr struct{ value []bool } +type TaskFlags struct{ value []bool } -// NewTaskFlagsAttr returns a value of `myapp.task.flags`. -func NewTaskFlagsAttr(value ...bool) TaskFlagsAttr { - return TaskFlagsAttr{value: value} +// NewTaskFlags returns a value of `myapp.task.flags`. +func NewTaskFlags(value ...bool) TaskFlags { + return TaskFlags{value: value} } // Key is the attribute key, for filters and views that need it. -func (TaskFlagsAttr) Key() attribute.Key { +func (TaskFlags) Key() attribute.Key { return taskFlagsKey } // KeyValue is the `myapp.task.flags` attribute set to this value. -func (v TaskFlagsAttr) KeyValue() attribute.KeyValue { +func (v TaskFlags) KeyValue() attribute.KeyValue { return taskFlagsKey.BoolSlice(v.value) } // taskIDKey is the attribute key of `myapp.task.id`. const taskIDKey = attribute.Key("myapp.task.id") -// TaskIDAttr is a value of `myapp.task.id`. +// TaskID is a value of `myapp.task.id`. // // Unique identifier of the task. // // The identifier is assigned by the scheduler and stays stable across // retries. -type TaskIDAttr struct{ value string } +type TaskID struct{ value string } -// NewTaskIDAttr returns a value of `myapp.task.id`. -func NewTaskIDAttr(value string) TaskIDAttr { - return TaskIDAttr{value: value} +// NewTaskID returns a value of `myapp.task.id`. +func NewTaskID(value string) TaskID { + return TaskID{value: value} } // Key is the attribute key, for filters and views that need it. -func (TaskIDAttr) Key() attribute.Key { +func (TaskID) Key() attribute.Key { return taskIDKey } // KeyValue is the `myapp.task.id` attribute set to this value. -func (v TaskIDAttr) KeyValue() attribute.KeyValue { +func (v TaskID) KeyValue() attribute.KeyValue { return taskIDKey.String(v.value) } @@ -107,20 +107,20 @@ func (v TaskIDAttr) KeyValue() attribute.KeyValue { // Deprecated: Lanes were replaced by priorities. const taskLaneKey = attribute.Key("myapp.task.lane") -// TaskLaneAttr is a value of `myapp.task.lane`. +// TaskLane is a value of `myapp.task.lane`. // // Lane the task was scheduled in. // // Deprecated: Lanes were replaced by priorities. -type TaskLaneAttr struct{ value string } +type TaskLane struct{ value string } // Key is the attribute key, for filters and views that need it. -func (TaskLaneAttr) Key() attribute.Key { +func (TaskLane) Key() attribute.Key { return taskLaneKey } // KeyValue is the `myapp.task.lane` attribute set to this value. -func (v TaskLaneAttr) KeyValue() attribute.KeyValue { +func (v TaskLane) KeyValue() attribute.KeyValue { return taskLaneKey.String(v.value) } @@ -130,14 +130,14 @@ var ( // The fast lane. // // Deprecated: Lanes were replaced by priorities. - TaskLaneFast = TaskLaneAttr{value: "fast"} + TaskLaneFast = TaskLane{value: "fast"} // TaskLaneSlow is the "slow" member of `myapp.task.lane`. // // The slow lane. // // Deprecated: Every task runs in the fast lane. - TaskLaneSlow = TaskLaneAttr{value: "slow"} + TaskLaneSlow = TaskLane{value: "slow"} ) // taskOwnerKey is the attribute key of `myapp.task.owner`. @@ -145,45 +145,45 @@ var ( // Deprecated: Replaced by `auth.user.id`. const taskOwnerKey = attribute.Key("myapp.task.owner") -// TaskOwnerAttr is a value of `myapp.task.owner`. +// TaskOwner is a value of `myapp.task.owner`. // // Owner of the task. // // Deprecated: Replaced by `auth.user.id`. -type TaskOwnerAttr struct{ value string } +type TaskOwner struct{ value string } -// NewTaskOwnerAttr returns a value of `myapp.task.owner`. +// NewTaskOwner returns a value of `myapp.task.owner`. // // Deprecated: Replaced by `auth.user.id`. -func NewTaskOwnerAttr(value string) TaskOwnerAttr { - return TaskOwnerAttr{value: value} +func NewTaskOwner(value string) TaskOwner { + return TaskOwner{value: value} } // Key is the attribute key, for filters and views that need it. -func (TaskOwnerAttr) Key() attribute.Key { +func (TaskOwner) Key() attribute.Key { return taskOwnerKey } // KeyValue is the `myapp.task.owner` attribute set to this value. -func (v TaskOwnerAttr) KeyValue() attribute.KeyValue { +func (v TaskOwner) KeyValue() attribute.KeyValue { return taskOwnerKey.String(v.value) } // taskPreemptibleKey is the attribute key of `myapp.task.preemptible`. const taskPreemptibleKey = attribute.Key("myapp.task.preemptible") -// TaskPreemptibleAttr is a value of `myapp.task.preemptible`. +// TaskPreemptible is a value of `myapp.task.preemptible`. // // Whether the scheduler may preempt the task. -type TaskPreemptibleAttr struct{ value bool } +type TaskPreemptible struct{ value bool } // Key is the attribute key, for filters and views that need it. -func (TaskPreemptibleAttr) Key() attribute.Key { +func (TaskPreemptible) Key() attribute.Key { return taskPreemptibleKey } // KeyValue is the `myapp.task.preemptible` attribute set to this value. -func (v TaskPreemptibleAttr) KeyValue() attribute.KeyValue { +func (v TaskPreemptible) KeyValue() attribute.KeyValue { return taskPreemptibleKey.Bool(v.value) } @@ -191,76 +191,76 @@ var ( // TaskPreemptibleAllowed is the true member of `myapp.task.preemptible`. // // The scheduler may preempt the task. - TaskPreemptibleAllowed = TaskPreemptibleAttr{value: true} + TaskPreemptibleAllowed = TaskPreemptible{value: true} // TaskPreemptibleForbidden is the false member of // `myapp.task.preemptible`. // // The task runs to completion. - TaskPreemptibleForbidden = TaskPreemptibleAttr{value: false} + TaskPreemptibleForbidden = TaskPreemptible{value: false} ) // taskProgressKey is the attribute key of `myapp.task.progress`. const taskProgressKey = attribute.Key("myapp.task.progress") -// TaskProgressAttr is a value of `myapp.task.progress`. +// TaskProgress is a value of `myapp.task.progress`. // // Fraction of the task that has completed, between 0 and 1. -type TaskProgressAttr struct{ value float64 } +type TaskProgress struct{ value float64 } -// NewTaskProgressAttr returns a value of `myapp.task.progress`. -func NewTaskProgressAttr(value float64) TaskProgressAttr { - return TaskProgressAttr{value: value} +// NewTaskProgress returns a value of `myapp.task.progress`. +func NewTaskProgress(value float64) TaskProgress { + return TaskProgress{value: value} } // Key is the attribute key, for filters and views that need it. -func (TaskProgressAttr) Key() attribute.Key { +func (TaskProgress) Key() attribute.Key { return taskProgressKey } // KeyValue is the `myapp.task.progress` attribute set to this value. -func (v TaskProgressAttr) KeyValue() attribute.KeyValue { +func (v TaskProgress) KeyValue() attribute.KeyValue { return taskProgressKey.Float64(v.value) } // taskRetriesKey is the attribute key of `myapp.task.retries`. const taskRetriesKey = attribute.Key("myapp.task.retries") -// TaskRetriesAttr is a value of `myapp.task.retries`. +// TaskRetries is a value of `myapp.task.retries`. // // Number of times the task was retried. -type TaskRetriesAttr struct{ value int } +type TaskRetries struct{ value int } -// NewTaskRetriesAttr returns a value of `myapp.task.retries`. -func NewTaskRetriesAttr(value int) TaskRetriesAttr { - return TaskRetriesAttr{value: value} +// NewTaskRetries returns a value of `myapp.task.retries`. +func NewTaskRetries(value int) TaskRetries { + return TaskRetries{value: value} } // Key is the attribute key, for filters and views that need it. -func (TaskRetriesAttr) Key() attribute.Key { +func (TaskRetries) Key() attribute.Key { return taskRetriesKey } // KeyValue is the `myapp.task.retries` attribute set to this value. -func (v TaskRetriesAttr) KeyValue() attribute.KeyValue { +func (v TaskRetries) KeyValue() attribute.KeyValue { return taskRetriesKey.Int(v.value) } // taskSampleRateKey is the attribute key of `myapp.task.sample_rate`. const taskSampleRateKey = attribute.Key("myapp.task.sample_rate") -// TaskSampleRateAttr is a value of `myapp.task.sample_rate`. +// TaskSampleRate is a value of `myapp.task.sample_rate`. // // Fraction of tasks whose telemetry is sampled. -type TaskSampleRateAttr struct{ value float64 } +type TaskSampleRate struct{ value float64 } // Key is the attribute key, for filters and views that need it. -func (TaskSampleRateAttr) Key() attribute.Key { +func (TaskSampleRate) Key() attribute.Key { return taskSampleRateKey } // KeyValue is the `myapp.task.sample_rate` attribute set to this value. -func (v TaskSampleRateAttr) KeyValue() attribute.KeyValue { +func (v TaskSampleRate) KeyValue() attribute.KeyValue { return taskSampleRateKey.Float64(v.value) } @@ -268,52 +268,52 @@ var ( // TaskSampleRateTenth is the 0.1 member of `myapp.task.sample_rate`. // // One task in ten is sampled. - TaskSampleRateTenth = TaskSampleRateAttr{value: 0.1} + TaskSampleRateTenth = TaskSampleRate{value: 0.1} // TaskSampleRateAll is the 1 member of `myapp.task.sample_rate`. // // Every task is sampled. - TaskSampleRateAll = TaskSampleRateAttr{value: 1} + TaskSampleRateAll = TaskSampleRate{value: 1} ) // taskShardIdsKey is the attribute key of `myapp.task.shard_ids`. const taskShardIdsKey = attribute.Key("myapp.task.shard_ids") -// TaskShardIdsAttr is a value of `myapp.task.shard_ids`. +// TaskShardIds is a value of `myapp.task.shard_ids`. // // Shards the task touched. -type TaskShardIdsAttr struct{ value []int } +type TaskShardIds struct{ value []int } -// NewTaskShardIdsAttr returns a value of `myapp.task.shard_ids`. -func NewTaskShardIdsAttr(value ...int) TaskShardIdsAttr { - return TaskShardIdsAttr{value: value} +// NewTaskShardIds returns a value of `myapp.task.shard_ids`. +func NewTaskShardIds(value ...int) TaskShardIds { + return TaskShardIds{value: value} } // Key is the attribute key, for filters and views that need it. -func (TaskShardIdsAttr) Key() attribute.Key { +func (TaskShardIds) Key() attribute.Key { return taskShardIdsKey } // KeyValue is the `myapp.task.shard_ids` attribute set to this value. -func (v TaskShardIdsAttr) KeyValue() attribute.KeyValue { +func (v TaskShardIds) KeyValue() attribute.KeyValue { return taskShardIdsKey.IntSlice(v.value) } // taskStateKey is the attribute key of `myapp.task.state`. const taskStateKey = attribute.Key("myapp.task.state") -// TaskStateAttr is a value of `myapp.task.state`. +// TaskState is a value of `myapp.task.state`. // // Current state of the task. -type TaskStateAttr struct{ value string } +type TaskState struct{ value string } // Key is the attribute key, for filters and views that need it. -func (TaskStateAttr) Key() attribute.Key { +func (TaskState) Key() attribute.Key { return taskStateKey } // KeyValue is the `myapp.task.state` attribute set to this value. -func (v TaskStateAttr) KeyValue() attribute.KeyValue { +func (v TaskState) KeyValue() attribute.KeyValue { return taskStateKey.String(v.value) } @@ -321,65 +321,65 @@ var ( // TaskStateQueued is the "queued" member of `myapp.task.state`. // // The task is waiting to run. - TaskStateQueued = TaskStateAttr{value: "queued"} + TaskStateQueued = TaskState{value: "queued"} // TaskStateRunning is the "running" member of `myapp.task.state`. // // The task is running. // // A task stays running until it finishes or is cancelled. - TaskStateRunning = TaskStateAttr{value: "running"} + TaskStateRunning = TaskState{value: "running"} // TaskStatePaused is the "paused" member of `myapp.task.state`. // // The task was paused. // // Deprecated: Paused tasks are reported as queued. - TaskStatePaused = TaskStateAttr{value: "paused"} + TaskStatePaused = TaskState{value: "paused"} ) // taskTagsKey is the attribute key of `myapp.task.tags`. const taskTagsKey = attribute.Key("myapp.task.tags") -// TaskTagsAttr is a value of `myapp.task.tags`. +// TaskTags is a value of `myapp.task.tags`. // // Tags attached to the task. -type TaskTagsAttr struct{ value []string } +type TaskTags struct{ value []string } -// NewTaskTagsAttr returns a value of `myapp.task.tags`. -func NewTaskTagsAttr(value ...string) TaskTagsAttr { - return TaskTagsAttr{value: value} +// NewTaskTags returns a value of `myapp.task.tags`. +func NewTaskTags(value ...string) TaskTags { + return TaskTags{value: value} } // Key is the attribute key, for filters and views that need it. -func (TaskTagsAttr) Key() attribute.Key { +func (TaskTags) Key() attribute.Key { return taskTagsKey } // KeyValue is the `myapp.task.tags` attribute set to this value. -func (v TaskTagsAttr) KeyValue() attribute.KeyValue { +func (v TaskTags) KeyValue() attribute.KeyValue { return taskTagsKey.StringSlice(v.value) } // taskWeightsKey is the attribute key of `myapp.task.weights`. const taskWeightsKey = attribute.Key("myapp.task.weights") -// TaskWeightsAttr is a value of `myapp.task.weights`. +// TaskWeights is a value of `myapp.task.weights`. // // Scheduling weights applied to the task. -type TaskWeightsAttr struct{ value []float64 } +type TaskWeights struct{ value []float64 } -// NewTaskWeightsAttr returns a value of `myapp.task.weights`. -func NewTaskWeightsAttr(value ...float64) TaskWeightsAttr { - return TaskWeightsAttr{value: value} +// NewTaskWeights returns a value of `myapp.task.weights`. +func NewTaskWeights(value ...float64) TaskWeights { + return TaskWeights{value: value} } // Key is the attribute key, for filters and views that need it. -func (TaskWeightsAttr) Key() attribute.Key { +func (TaskWeights) Key() attribute.Key { return taskWeightsKey } // KeyValue is the `myapp.task.weights` attribute set to this value. -func (v TaskWeightsAttr) KeyValue() attribute.KeyValue { +func (v TaskWeights) KeyValue() attribute.KeyValue { return taskWeightsKey.Float64Slice(v.value) } diff --git a/templates/code/go/tests/entities/expected/myappattr/attributes.go b/templates/code/go/tests/entities/expected/myappattr/attributes.go index e32ccef..e6de88c 100644 --- a/templates/code/go/tests/entities/expected/myappattr/attributes.go +++ b/templates/code/go/tests/entities/expected/myappattr/attributes.go @@ -9,91 +9,91 @@ import "go.opentelemetry.io/otel/attribute" // Deprecated: Use `myapp.host.cpu.logical_count` instead. const hostCPUCountKey = attribute.Key("myapp.host.cpu.count") -// HostCPUCountAttr is a value of `myapp.host.cpu.count`. +// HostCPUCount is a value of `myapp.host.cpu.count`. // // Number of CPUs the host has. // // Deprecated: Use `myapp.host.cpu.logical_count` instead. -type HostCPUCountAttr struct{ value int } +type HostCPUCount struct{ value int } -// NewHostCPUCountAttr returns a value of `myapp.host.cpu.count`. +// NewHostCPUCount returns a value of `myapp.host.cpu.count`. // // Deprecated: Use `myapp.host.cpu.logical_count` instead. -func NewHostCPUCountAttr(value int) HostCPUCountAttr { - return HostCPUCountAttr{value: value} +func NewHostCPUCount(value int) HostCPUCount { + return HostCPUCount{value: value} } // Key is the attribute key, for filters and views that need it. -func (HostCPUCountAttr) Key() attribute.Key { +func (HostCPUCount) Key() attribute.Key { return hostCPUCountKey } // KeyValue is the `myapp.host.cpu.count` attribute set to this value. -func (v HostCPUCountAttr) KeyValue() attribute.KeyValue { +func (v HostCPUCount) KeyValue() attribute.KeyValue { return hostCPUCountKey.Int(v.value) } // hostNameKey is the attribute key of `myapp.host.name`. const hostNameKey = attribute.Key("myapp.host.name") -// HostNameAttr is a value of `myapp.host.name`. +// HostName is a value of `myapp.host.name`. // // Name of the host. -type HostNameAttr struct{ value string } +type HostName struct{ value string } -// NewHostNameAttr returns a value of `myapp.host.name`. -func NewHostNameAttr(value string) HostNameAttr { - return HostNameAttr{value: value} +// NewHostName returns a value of `myapp.host.name`. +func NewHostName(value string) HostName { + return HostName{value: value} } // Key is the attribute key, for filters and views that need it. -func (HostNameAttr) Key() attribute.Key { +func (HostName) Key() attribute.Key { return hostNameKey } // KeyValue is the `myapp.host.name` attribute set to this value. -func (v HostNameAttr) KeyValue() attribute.KeyValue { +func (v HostName) KeyValue() attribute.KeyValue { return hostNameKey.String(v.value) } // hostRoleKey is the attribute key of `myapp.host.role`. const hostRoleKey = attribute.Key("myapp.host.role") -// HostRoleAttr is a value of `myapp.host.role`. +// HostRole is a value of `myapp.host.role`. // // Role the host plays in the cluster. -type HostRoleAttr struct{ value string } +type HostRole struct{ value string } -// NewHostRoleAttr returns a value of `myapp.host.role`. -func NewHostRoleAttr(value string) HostRoleAttr { - return HostRoleAttr{value: value} +// NewHostRole returns a value of `myapp.host.role`. +func NewHostRole(value string) HostRole { + return HostRole{value: value} } // Key is the attribute key, for filters and views that need it. -func (HostRoleAttr) Key() attribute.Key { +func (HostRole) Key() attribute.Key { return hostRoleKey } // KeyValue is the `myapp.host.role` attribute set to this value. -func (v HostRoleAttr) KeyValue() attribute.KeyValue { +func (v HostRole) KeyValue() attribute.KeyValue { return hostRoleKey.String(v.value) } // hostTypeKey is the attribute key of `myapp.host.type`. const hostTypeKey = attribute.Key("myapp.host.type") -// HostTypeAttr is a value of `myapp.host.type`. +// HostType is a value of `myapp.host.type`. // // Type of the host. -type HostTypeAttr struct{ value string } +type HostType struct{ value string } // Key is the attribute key, for filters and views that need it. -func (HostTypeAttr) Key() attribute.Key { +func (HostType) Key() attribute.Key { return hostTypeKey } // KeyValue is the `myapp.host.type` attribute set to this value. -func (v HostTypeAttr) KeyValue() attribute.KeyValue { +func (v HostType) KeyValue() attribute.KeyValue { return hostTypeKey.String(v.value) } @@ -101,56 +101,56 @@ var ( // HostTypePhysical is the "physical" member of `myapp.host.type`. // // A physical host. - HostTypePhysical = HostTypeAttr{value: "physical"} + HostTypePhysical = HostType{value: "physical"} // HostTypeVirtual is the "virtual" member of `myapp.host.type`. // // A virtual host. - HostTypeVirtual = HostTypeAttr{value: "virtual"} + HostTypeVirtual = HostType{value: "virtual"} ) // queueNameKey is the attribute key of `myapp.queue.name`. const queueNameKey = attribute.Key("myapp.queue.name") -// QueueNameAttr is a value of `myapp.queue.name`. +// QueueName is a value of `myapp.queue.name`. // // Name of the queue. -type QueueNameAttr struct{ value string } +type QueueName struct{ value string } -// NewQueueNameAttr returns a value of `myapp.queue.name`. -func NewQueueNameAttr(value string) QueueNameAttr { - return QueueNameAttr{value: value} +// NewQueueName returns a value of `myapp.queue.name`. +func NewQueueName(value string) QueueName { + return QueueName{value: value} } // Key is the attribute key, for filters and views that need it. -func (QueueNameAttr) Key() attribute.Key { +func (QueueName) Key() attribute.Key { return queueNameKey } // KeyValue is the `myapp.queue.name` attribute set to this value. -func (v QueueNameAttr) KeyValue() attribute.KeyValue { +func (v QueueName) KeyValue() attribute.KeyValue { return queueNameKey.String(v.value) } // queueSizeKey is the attribute key of `myapp.queue.size`. const queueSizeKey = attribute.Key("myapp.queue.size") -// QueueSizeAttr is a value of `myapp.queue.size`. +// QueueSize is a value of `myapp.queue.size`. // // Number of items currently in the queue. -type QueueSizeAttr struct{ value int } +type QueueSize struct{ value int } -// NewQueueSizeAttr returns a value of `myapp.queue.size`. -func NewQueueSizeAttr(value int) QueueSizeAttr { - return QueueSizeAttr{value: value} +// NewQueueSize returns a value of `myapp.queue.size`. +func NewQueueSize(value int) QueueSize { + return QueueSize{value: value} } // Key is the attribute key, for filters and views that need it. -func (QueueSizeAttr) Key() attribute.Key { +func (QueueSize) Key() attribute.Key { return queueSizeKey } // KeyValue is the `myapp.queue.size` attribute set to this value. -func (v QueueSizeAttr) KeyValue() attribute.KeyValue { +func (v QueueSize) KeyValue() attribute.KeyValue { return queueSizeKey.Int(v.value) } diff --git a/templates/code/go/tests/entities/expected/myappentity/entities.go b/templates/code/go/tests/entities/expected/myappentity/entities.go index 34ffd6f..c82f47e 100644 --- a/templates/code/go/tests/entities/expected/myappentity/entities.go +++ b/templates/code/go/tests/entities/expected/myappentity/entities.go @@ -11,38 +11,37 @@ import ( "example.com/semconv" ) -// HostEntityAttr is an attribute NewHostEntity accepts in addition to the -// ones it requires. -type HostEntityAttr interface { +// HostAttr is an attribute NewHost accepts in addition to the ones it +// requires. +type HostAttr interface { hostEntityAttr() attribute.KeyValue } -type hostEntityHostCPUCount struct{ v myappattr.HostCPUCountAttr } +type hostEntityHostCPUCount struct{ v myappattr.HostCPUCount } func (o hostEntityHostCPUCount) hostEntityAttr() attribute.KeyValue { return o.v.KeyValue() } -// WithHostEntityHostCPUCount sets `myapp.host.cpu.count` on the entity. +// WithHostHostCPUCount sets `myapp.host.cpu.count` on the entity. // // Opt-in: the convention records it only when a user asks for it. -func WithHostEntityHostCPUCount(v myappattr.HostCPUCountAttr) HostEntityAttr { +func WithHostHostCPUCount(v myappattr.HostCPUCount) HostAttr { return hostEntityHostCPUCount{v: v} } -type hostEntityHostType struct{ v myappattr.HostTypeAttr } +type hostEntityHostType struct{ v myappattr.HostType } func (o hostEntityHostType) hostEntityAttr() attribute.KeyValue { return o.v.KeyValue() } -// WithHostEntityHostType sets `myapp.host.type` on the entity. -func WithHostEntityHostType(v myappattr.HostTypeAttr) HostEntityAttr { +// WithHostHostType sets `myapp.host.type` on the entity. +func WithHostHostType(v myappattr.HostType) HostAttr { return hostEntityHostType{v: v} } -// HostEntity is the `myapp.host` entity. The zero HostEntity has no -// attributes. +// Host is the `myapp.host` entity. The zero Host has no attributes. // // A host running the application. // @@ -51,22 +50,21 @@ func WithHostEntityHostType(v myappattr.HostTypeAttr) HostEntityAttr { // Identifies the entity: `myapp.host.name`. // // Describes the entity: `myapp.host.cpu.count`, `myapp.host.type`. -type HostEntity struct{ attrs []attribute.KeyValue } +type Host struct{ attrs []attribute.KeyValue } -// NewHostEntity builds a HostEntity from its required attributes and any -// given options. -func NewHostEntity(myappHostName myappattr.HostNameAttr, opts ...HostEntityAttr) HostEntity { +// NewHost builds a Host from its required attributes and any given options. +func NewHost(myappHostName myappattr.HostName, opts ...HostAttr) Host { attrs := make([]attribute.KeyValue, 0, 1+len(opts)) attrs = append(attrs, myappHostName.KeyValue()) for _, opt := range opts { attrs = append(attrs, opt.hostEntityAttr()) } - return HostEntity{attrs: attrs} + return Host{attrs: attrs} } -// Attributes returns a copy of the entity's attributes. The zero HostEntity +// Attributes returns a copy of the entity's attributes. The zero Host // returns none. -func (e HostEntity) Attributes() []attribute.KeyValue { +func (e Host) Attributes() []attribute.KeyValue { out := make([]attribute.KeyValue, len(e.attrs)) copy(out, e.attrs) return out @@ -74,43 +72,42 @@ func (e HostEntity) Attributes() []attribute.KeyValue { // Resource returns a *resource.Resource built from the entity's attributes, // tied to semconv.SchemaURL. -func (e HostEntity) Resource() *resource.Resource { +func (e Host) Resource() *resource.Resource { return resource.NewWithAttributes(semconv.SchemaURL, e.attrs...) } -// HostWorkerEntityAttr is an attribute NewHostWorkerEntity accepts in -// addition to the ones it requires. -type HostWorkerEntityAttr interface { +// HostWorkerAttr is an attribute NewHostWorker accepts in addition to the +// ones it requires. +type HostWorkerAttr interface { hostWorkerEntityAttr() attribute.KeyValue } -type hostWorkerEntityHostCPUCount struct{ v myappattr.HostCPUCountAttr } +type hostWorkerEntityHostCPUCount struct{ v myappattr.HostCPUCount } func (o hostWorkerEntityHostCPUCount) hostWorkerEntityAttr() attribute.KeyValue { return o.v.KeyValue() } -// WithHostWorkerEntityHostCPUCount sets `myapp.host.cpu.count` on the -// entity. +// WithHostWorkerHostCPUCount sets `myapp.host.cpu.count` on the entity. // // Opt-in: the convention records it only when a user asks for it. -func WithHostWorkerEntityHostCPUCount(v myappattr.HostCPUCountAttr) HostWorkerEntityAttr { +func WithHostWorkerHostCPUCount(v myappattr.HostCPUCount) HostWorkerAttr { return hostWorkerEntityHostCPUCount{v: v} } -type hostWorkerEntityHostType struct{ v myappattr.HostTypeAttr } +type hostWorkerEntityHostType struct{ v myappattr.HostType } func (o hostWorkerEntityHostType) hostWorkerEntityAttr() attribute.KeyValue { return o.v.KeyValue() } -// WithHostWorkerEntityHostType sets `myapp.host.type` on the entity. -func WithHostWorkerEntityHostType(v myappattr.HostTypeAttr) HostWorkerEntityAttr { +// WithHostWorkerHostType sets `myapp.host.type` on the entity. +func WithHostWorkerHostType(v myappattr.HostType) HostWorkerAttr { return hostWorkerEntityHostType{v: v} } -// HostWorkerEntity is the `myapp.host.worker` entity, a refinement of -// `myapp.host`. The zero HostWorkerEntity has no attributes. +// HostWorker is the `myapp.host.worker` entity, a refinement of `myapp.host`. +// The zero HostWorker has no attributes. // // A host dedicated to running worker processes. // @@ -120,23 +117,23 @@ func WithHostWorkerEntityHostType(v myappattr.HostTypeAttr) HostWorkerEntityAttr // // Describes the entity: `myapp.host.cpu.count`, `myapp.host.role`, // `myapp.host.type`. -type HostWorkerEntity struct{ attrs []attribute.KeyValue } +type HostWorker struct{ attrs []attribute.KeyValue } -// NewHostWorkerEntity builds a HostWorkerEntity from its required attributes -// and any given options. -func NewHostWorkerEntity(myappHostName myappattr.HostNameAttr, myappHostRole myappattr.HostRoleAttr, opts ...HostWorkerEntityAttr) HostWorkerEntity { +// NewHostWorker builds a HostWorker from its required attributes and any +// given options. +func NewHostWorker(myappHostName myappattr.HostName, myappHostRole myappattr.HostRole, opts ...HostWorkerAttr) HostWorker { attrs := make([]attribute.KeyValue, 0, 2+len(opts)) attrs = append(attrs, myappHostName.KeyValue()) attrs = append(attrs, myappHostRole.KeyValue()) for _, opt := range opts { attrs = append(attrs, opt.hostWorkerEntityAttr()) } - return HostWorkerEntity{attrs: attrs} + return HostWorker{attrs: attrs} } -// Attributes returns a copy of the entity's attributes. The zero -// HostWorkerEntity returns none. -func (e HostWorkerEntity) Attributes() []attribute.KeyValue { +// Attributes returns a copy of the entity's attributes. The zero HostWorker +// returns none. +func (e HostWorker) Attributes() []attribute.KeyValue { out := make([]attribute.KeyValue, len(e.attrs)) copy(out, e.attrs) return out @@ -144,51 +141,50 @@ func (e HostWorkerEntity) Attributes() []attribute.KeyValue { // Resource returns a *resource.Resource built from the entity's attributes, // tied to semconv.SchemaURL. -func (e HostWorkerEntity) Resource() *resource.Resource { +func (e HostWorker) Resource() *resource.Resource { return resource.NewWithAttributes(semconv.SchemaURL, e.attrs...) } -// QueueEntityAttr is an attribute NewQueueEntity accepts in addition to the -// ones it requires. -type QueueEntityAttr interface { +// QueueAttr is an attribute NewQueue accepts in addition to the ones it +// requires. +type QueueAttr interface { queueEntityAttr() attribute.KeyValue } -type queueEntityQueueSize struct{ v myappattr.QueueSizeAttr } +type queueEntityQueueSize struct{ v myappattr.QueueSize } func (o queueEntityQueueSize) queueEntityAttr() attribute.KeyValue { return o.v.KeyValue() } -// WithQueueEntityQueueSize sets `myapp.queue.size` on the entity. -func WithQueueEntityQueueSize(v myappattr.QueueSizeAttr) QueueEntityAttr { +// WithQueueQueueSize sets `myapp.queue.size` on the entity. +func WithQueueQueueSize(v myappattr.QueueSize) QueueAttr { return queueEntityQueueSize{v: v} } -// QueueEntity is the `myapp.queue` entity. The zero QueueEntity has no -// attributes. +// Queue is the `myapp.queue` entity. The zero Queue has no attributes. // // A queue of tasks. // // Identifies the entity: `myapp.queue.name`. // // Describes the entity: `myapp.queue.size`. -type QueueEntity struct{ attrs []attribute.KeyValue } +type Queue struct{ attrs []attribute.KeyValue } -// NewQueueEntity builds a QueueEntity from its required attributes and any -// given options. -func NewQueueEntity(myappQueueName myappattr.QueueNameAttr, opts ...QueueEntityAttr) QueueEntity { +// NewQueue builds a Queue from its required attributes and any given +// options. +func NewQueue(myappQueueName myappattr.QueueName, opts ...QueueAttr) Queue { attrs := make([]attribute.KeyValue, 0, 1+len(opts)) attrs = append(attrs, myappQueueName.KeyValue()) for _, opt := range opts { attrs = append(attrs, opt.queueEntityAttr()) } - return QueueEntity{attrs: attrs} + return Queue{attrs: attrs} } -// Attributes returns a copy of the entity's attributes. The zero QueueEntity +// Attributes returns a copy of the entity's attributes. The zero Queue // returns none. -func (e QueueEntity) Attributes() []attribute.KeyValue { +func (e Queue) Attributes() []attribute.KeyValue { out := make([]attribute.KeyValue, len(e.attrs)) copy(out, e.attrs) return out @@ -196,6 +192,6 @@ func (e QueueEntity) Attributes() []attribute.KeyValue { // Resource returns a *resource.Resource built from the entity's attributes, // tied to semconv.SchemaURL. -func (e QueueEntity) Resource() *resource.Resource { +func (e Queue) Resource() *resource.Resource { return resource.NewWithAttributes(semconv.SchemaURL, e.attrs...) } diff --git a/templates/code/go/tests/error_attribute_member_collision/expected-error.txt b/templates/code/go/tests/error_attribute_member_collision/expected-error.txt new file mode 100644 index 0000000..16ce069 --- /dev/null +++ b/templates/code/go/tests/error_attribute_member_collision/expected-error.txt @@ -0,0 +1 @@ +package myappattr has attributes that render to the same Go identifier: myapp.task.state and myapp.task.state.done diff --git a/templates/code/go/tests/error_attribute_member_collision/registry/manifest.yaml b/templates/code/go/tests/error_attribute_member_collision/registry/manifest.yaml new file mode 100644 index 0000000..ed00442 --- /dev/null +++ b/templates/code/go/tests/error_attribute_member_collision/registry/manifest.yaml @@ -0,0 +1,2 @@ +name: error_attribute_member_collision +schema_url: https://example.com/schemas/error_attribute_member_collision/1.0.0 diff --git a/templates/code/go/tests/error_attribute_member_collision/registry/myapp.yaml b/templates/code/go/tests/error_attribute_member_collision/registry/myapp.yaml new file mode 100644 index 0000000..93cb585 --- /dev/null +++ b/templates/code/go/tests/error_attribute_member_collision/registry/myapp.yaml @@ -0,0 +1,17 @@ +file_format: definition/2 +attributes: + - key: myapp.task.state + type: + members: + - id: done + value: done + stability: stable + brief: The task finished. + stability: stable + brief: State of the task. + examples: ["done"] + - key: myapp.task.state.done + type: boolean + stability: stable + brief: Whether the task finished. + examples: [true] diff --git a/templates/code/go/tests/error_entity_attr_collision/expected-error.txt b/templates/code/go/tests/error_entity_attr_collision/expected-error.txt new file mode 100644 index 0000000..5f66e7d --- /dev/null +++ b/templates/code/go/tests/error_entity_attr_collision/expected-error.txt @@ -0,0 +1 @@ +package myappentity has entities that render to the same Go identifier: myapp.host and myapp.host.attr diff --git a/templates/code/go/tests/error_entity_attr_collision/registry/manifest.yaml b/templates/code/go/tests/error_entity_attr_collision/registry/manifest.yaml new file mode 100644 index 0000000..a6dc9f5 --- /dev/null +++ b/templates/code/go/tests/error_entity_attr_collision/registry/manifest.yaml @@ -0,0 +1,2 @@ +name: error_entity_attr_collision +schema_url: https://example.com/schemas/error_entity_attr_collision/1.0.0 diff --git a/templates/code/go/tests/error_entity_attr_collision/registry/myapp.yaml b/templates/code/go/tests/error_entity_attr_collision/registry/myapp.yaml new file mode 100644 index 0000000..a798b03 --- /dev/null +++ b/templates/code/go/tests/error_entity_attr_collision/registry/myapp.yaml @@ -0,0 +1,30 @@ +file_format: definition/2 +attributes: + - key: myapp.host.id + type: string + stability: stable + brief: Unique identifier of the host. + examples: ["h-1"] + - key: myapp.host.type + type: string + stability: stable + brief: Type of the host. + examples: ["vm"] +entities: + - type: myapp.host + requirement_level: recommended + stability: stable + brief: A host. + identity: + - ref: myapp.host.id + requirement_level: required + description: + - ref: myapp.host.type + requirement_level: recommended + - type: myapp.host.attr + requirement_level: recommended + stability: stable + brief: An entity whose type shares the name of another entity's option type. + identity: + - ref: myapp.host.id + requirement_level: required diff --git a/templates/code/go/tests/error_metric_attr_collision/expected-error.txt b/templates/code/go/tests/error_metric_attr_collision/expected-error.txt new file mode 100644 index 0000000..d9e40f4 --- /dev/null +++ b/templates/code/go/tests/error_metric_attr_collision/expected-error.txt @@ -0,0 +1 @@ +package myappmetric has metrics that render to the same Go identifier: myapp.task.duration and myapp.task.duration.attr diff --git a/templates/code/go/tests/error_metric_attr_collision/registry/manifest.yaml b/templates/code/go/tests/error_metric_attr_collision/registry/manifest.yaml new file mode 100644 index 0000000..831d7c5 --- /dev/null +++ b/templates/code/go/tests/error_metric_attr_collision/registry/manifest.yaml @@ -0,0 +1,2 @@ +name: error_metric_attr_collision +schema_url: https://example.com/schemas/error_metric_attr_collision/1.0.0 diff --git a/templates/code/go/tests/error_metric_attr_collision/registry/model.yaml b/templates/code/go/tests/error_metric_attr_collision/registry/model.yaml new file mode 100644 index 0000000..31df5c8 --- /dev/null +++ b/templates/code/go/tests/error_metric_attr_collision/registry/model.yaml @@ -0,0 +1,27 @@ +file_format: definition/2 +attributes: + - key: myapp.task.id + type: string + stability: stable + brief: Unique identifier of the task. + examples: ["task_0001"] +metrics: + - name: myapp.task.duration + instrument: histogram + unit: s + stability: stable + brief: Time a task took. + attributes: + - ref: myapp.task.id + requirement_level: recommended + annotations: + code_generation: + metric_value_type: double + - name: myapp.task.duration.attr + instrument: counter + unit: "{task}" + stability: stable + brief: A metric whose type shares the name of another metric's attribute option. + annotations: + code_generation: + metric_value_type: int diff --git a/templates/code/go/tests/error_span_name_collision/expected-error.txt b/templates/code/go/tests/error_span_name_collision/expected-error.txt new file mode 100644 index 0000000..a079072 --- /dev/null +++ b/templates/code/go/tests/error_span_name_collision/expected-error.txt @@ -0,0 +1 @@ +package myappspan has spans that render to the same Go identifier: myapp.task.run and myapp.task.run.name diff --git a/templates/code/go/tests/error_span_name_collision/registry/manifest.yaml b/templates/code/go/tests/error_span_name_collision/registry/manifest.yaml new file mode 100644 index 0000000..b74e5d9 --- /dev/null +++ b/templates/code/go/tests/error_span_name_collision/registry/manifest.yaml @@ -0,0 +1,2 @@ +name: error_span_name_collision +schema_url: https://example.com/schemas/error_span_name_collision/1.0.0 diff --git a/templates/code/go/tests/error_span_name_collision/registry/myapp.yaml b/templates/code/go/tests/error_span_name_collision/registry/myapp.yaml new file mode 100644 index 0000000..730b4a2 --- /dev/null +++ b/templates/code/go/tests/error_span_name_collision/registry/myapp.yaml @@ -0,0 +1,16 @@ +file_format: definition/2 +spans: + - type: myapp.task.run + kind: internal + name: + note: "" + requirement_level: recommended + stability: stable + brief: One run of a task. + - type: myapp.task.run.name + kind: internal + name: + note: "" + requirement_level: recommended + stability: stable + brief: A span whose type shares the name of another span's typed name. diff --git a/templates/code/go/tests/events/expected/myappattr/attributes.go b/templates/code/go/tests/events/expected/myappattr/attributes.go index 4bca834..992b6c5 100644 --- a/templates/code/go/tests/events/expected/myappattr/attributes.go +++ b/templates/code/go/tests/events/expected/myappattr/attributes.go @@ -7,41 +7,41 @@ import "go.opentelemetry.io/otel/attribute" // taskAttemptKey is the attribute key of `myapp.task.attempt`. const taskAttemptKey = attribute.Key("myapp.task.attempt") -// TaskAttemptAttr is a value of `myapp.task.attempt`. +// TaskAttempt is a value of `myapp.task.attempt`. // // Number of the attempt, starting at 1. -type TaskAttemptAttr struct{ value int } +type TaskAttempt struct{ value int } -// NewTaskAttemptAttr returns a value of `myapp.task.attempt`. -func NewTaskAttemptAttr(value int) TaskAttemptAttr { - return TaskAttemptAttr{value: value} +// NewTaskAttempt returns a value of `myapp.task.attempt`. +func NewTaskAttempt(value int) TaskAttempt { + return TaskAttempt{value: value} } // Key is the attribute key, for filters and views that need it. -func (TaskAttemptAttr) Key() attribute.Key { +func (TaskAttempt) Key() attribute.Key { return taskAttemptKey } // KeyValue is the `myapp.task.attempt` attribute set to this value. -func (v TaskAttemptAttr) KeyValue() attribute.KeyValue { +func (v TaskAttempt) KeyValue() attribute.KeyValue { return taskAttemptKey.Int(v.value) } // taskStateKey is the attribute key of `myapp.task.state`. const taskStateKey = attribute.Key("myapp.task.state") -// TaskStateAttr is a value of `myapp.task.state`. +// TaskState is a value of `myapp.task.state`. // // Current state of the task. -type TaskStateAttr struct{ value string } +type TaskState struct{ value string } // Key is the attribute key, for filters and views that need it. -func (TaskStateAttr) Key() attribute.Key { +func (TaskState) Key() attribute.Key { return taskStateKey } // KeyValue is the `myapp.task.state` attribute set to this value. -func (v TaskStateAttr) KeyValue() attribute.KeyValue { +func (v TaskState) KeyValue() attribute.KeyValue { return taskStateKey.String(v.value) } @@ -49,10 +49,10 @@ var ( // TaskStateDone is the "done" member of `myapp.task.state`. // // The task finished. - TaskStateDone = TaskStateAttr{value: "done"} + TaskStateDone = TaskState{value: "done"} // TaskStateFailed is the "failed" member of `myapp.task.state`. // // The task gave up. - TaskStateFailed = TaskStateAttr{value: "failed"} + TaskStateFailed = TaskState{value: "failed"} ) diff --git a/templates/code/go/tests/events/expected/myappevent/events.go b/templates/code/go/tests/events/expected/myappevent/events.go index 04f1808..00a98df 100644 --- a/templates/code/go/tests/events/expected/myappevent/events.go +++ b/templates/code/go/tests/events/expected/myappevent/events.go @@ -43,7 +43,7 @@ func WithTaskFinishedTimestamp(timestamp time.Time) TaskFinishedOption { return taskFinishedEventTimestamp{v: timestamp} } -type taskFinishedEventTaskAttempt struct{ v myappattr.TaskAttemptAttr } +type taskFinishedEventTaskAttempt struct{ v myappattr.TaskAttempt } func (o taskFinishedEventTaskAttempt) taskFinishedOption(record *log.Record) { record.AddAttributes(o.v.KeyValue()) @@ -52,11 +52,11 @@ func (o taskFinishedEventTaskAttempt) taskFinishedOption(record *log.Record) { // WithTaskFinishedTaskAttempt sets `myapp.task.attempt` on the event. // // Recommended: When the task ran more than once. -func WithTaskFinishedTaskAttempt(v myappattr.TaskAttemptAttr) TaskFinishedOption { +func WithTaskFinishedTaskAttempt(v myappattr.TaskAttempt) TaskFinishedOption { return taskFinishedEventTaskAttempt{v: v} } -type taskFinishedEventHostName struct{ v workerattr.HostNameAttr } +type taskFinishedEventHostName struct{ v workerattr.HostName } func (o taskFinishedEventHostName) taskFinishedOption(record *log.Record) { record.AddAttributes(o.v.KeyValue()) @@ -65,7 +65,7 @@ func (o taskFinishedEventHostName) taskFinishedOption(record *log.Record) { // WithTaskFinishedHostName sets `worker.host.name` on the event. // // Opt-in: the convention records it only when a user asks for it. -func WithTaskFinishedHostName(v workerattr.HostNameAttr) TaskFinishedOption { +func WithTaskFinishedHostName(v workerattr.HostName) TaskFinishedOption { return taskFinishedEventHostName{v: v} } @@ -76,7 +76,7 @@ func WithTaskFinishedHostName(v workerattr.HostNameAttr) TaskFinishedOption { // A task reached a final state. // // Emitted once per task, after its last attempt. -func EmitTaskFinished(ctx context.Context, logger semconvlogger.Logger, myappTaskState myappattr.TaskStateAttr, opts ...TaskFinishedOption) { +func EmitTaskFinished(ctx context.Context, logger semconvlogger.Logger, myappTaskState myappattr.TaskState, opts ...TaskFinishedOption) { var record log.Record record.SetEventName("myapp.task.finished") record.SetSeverity(log.SeverityInfo) @@ -132,7 +132,7 @@ func WithTaskRetriedTimestamp(timestamp time.Time) TaskRetriedOption { // for it. // // Deprecated: Read the attempt from `myapp.task.finished` instead. -func EmitTaskRetried(ctx context.Context, logger semconvlogger.Logger, myappTaskAttempt myappattr.TaskAttemptAttr, opts ...TaskRetriedOption) { +func EmitTaskRetried(ctx context.Context, logger semconvlogger.Logger, myappTaskAttempt myappattr.TaskAttempt, opts ...TaskRetriedOption) { var record log.Record record.SetEventName("myapp.task.retried") record.SetSeverity(log.SeverityInfo) diff --git a/templates/code/go/tests/events/expected/workerattr/attributes.go b/templates/code/go/tests/events/expected/workerattr/attributes.go index 6e3ae9f..4206cbd 100644 --- a/templates/code/go/tests/events/expected/workerattr/attributes.go +++ b/templates/code/go/tests/events/expected/workerattr/attributes.go @@ -7,22 +7,22 @@ import "go.opentelemetry.io/otel/attribute" // hostNameKey is the attribute key of `worker.host.name`. const hostNameKey = attribute.Key("worker.host.name") -// HostNameAttr is a value of `worker.host.name`. +// HostName is a value of `worker.host.name`. // // Name of the worker host. -type HostNameAttr struct{ value string } +type HostName struct{ value string } -// NewHostNameAttr returns a value of `worker.host.name`. -func NewHostNameAttr(value string) HostNameAttr { - return HostNameAttr{value: value} +// NewHostName returns a value of `worker.host.name`. +func NewHostName(value string) HostName { + return HostName{value: value} } // Key is the attribute key, for filters and views that need it. -func (HostNameAttr) Key() attribute.Key { +func (HostName) Key() attribute.Key { return hostNameKey } // KeyValue is the `worker.host.name` attribute set to this value. -func (v HostNameAttr) KeyValue() attribute.KeyValue { +func (v HostName) KeyValue() attribute.KeyValue { return hostNameKey.String(v.value) } diff --git a/templates/code/go/tests/events/expected/workerevent/events.go b/templates/code/go/tests/events/expected/workerevent/events.go index 87bb424..1b89f9c 100644 --- a/templates/code/go/tests/events/expected/workerevent/events.go +++ b/templates/code/go/tests/events/expected/workerevent/events.go @@ -91,7 +91,7 @@ func WithTaskFinishedTimestamp(timestamp time.Time) TaskFinishedOption { return taskFinishedEventTimestamp{v: timestamp} } -type taskFinishedEventTaskAttempt struct{ v myappattr.TaskAttemptAttr } +type taskFinishedEventTaskAttempt struct{ v myappattr.TaskAttempt } func (o taskFinishedEventTaskAttempt) taskFinishedOption(record *log.Record) { record.AddAttributes(o.v.KeyValue()) @@ -100,7 +100,7 @@ func (o taskFinishedEventTaskAttempt) taskFinishedOption(record *log.Record) { // WithTaskFinishedTaskAttempt sets `myapp.task.attempt` on the event. // // Recommended: When the task ran more than once. -func WithTaskFinishedTaskAttempt(v myappattr.TaskAttemptAttr) TaskFinishedOption { +func WithTaskFinishedTaskAttempt(v myappattr.TaskAttempt) TaskFinishedOption { return taskFinishedEventTaskAttempt{v: v} } @@ -111,7 +111,7 @@ func WithTaskFinishedTaskAttempt(v myappattr.TaskAttemptAttr) TaskFinishedOption // A task reached a final state on a worker. // // Emitted once per task, after its last attempt. -func EmitTaskFinished(ctx context.Context, logger semconvlogger.Logger, myappTaskState myappattr.TaskStateAttr, workerHostName workerattr.HostNameAttr, opts ...TaskFinishedOption) { +func EmitTaskFinished(ctx context.Context, logger semconvlogger.Logger, myappTaskState myappattr.TaskState, workerHostName workerattr.HostName, opts ...TaskFinishedOption) { var record log.Record record.SetEventName("worker.task.finished") record.SetSeverity(log.SeverityInfo) diff --git a/templates/code/go/tests/histogram_boundaries_by_unit/expected/myappattr/attributes.go b/templates/code/go/tests/histogram_boundaries_by_unit/expected/myappattr/attributes.go index 2e0bf1d..d20b02e 100644 --- a/templates/code/go/tests/histogram_boundaries_by_unit/expected/myappattr/attributes.go +++ b/templates/code/go/tests/histogram_boundaries_by_unit/expected/myappattr/attributes.go @@ -7,22 +7,22 @@ import "go.opentelemetry.io/otel/attribute" // taskIDKey is the attribute key of `myapp.task.id`. const taskIDKey = attribute.Key("myapp.task.id") -// TaskIDAttr is a value of `myapp.task.id`. +// TaskID is a value of `myapp.task.id`. // // Unique identifier of the task. -type TaskIDAttr struct{ value string } +type TaskID struct{ value string } -// NewTaskIDAttr returns a value of `myapp.task.id`. -func NewTaskIDAttr(value string) TaskIDAttr { - return TaskIDAttr{value: value} +// NewTaskID returns a value of `myapp.task.id`. +func NewTaskID(value string) TaskID { + return TaskID{value: value} } // Key is the attribute key, for filters and views that need it. -func (TaskIDAttr) Key() attribute.Key { +func (TaskID) Key() attribute.Key { return taskIDKey } // KeyValue is the `myapp.task.id` attribute set to this value. -func (v TaskIDAttr) KeyValue() attribute.KeyValue { +func (v TaskID) KeyValue() attribute.KeyValue { return taskIDKey.String(v.value) } diff --git a/templates/code/go/tests/histogram_boundaries_by_unit/expected/myappmetric/metrics.go b/templates/code/go/tests/histogram_boundaries_by_unit/expected/myappmetric/metrics.go index 7161168..65e79c3 100644 --- a/templates/code/go/tests/histogram_boundaries_by_unit/expected/myappmetric/metrics.go +++ b/templates/code/go/tests/histogram_boundaries_by_unit/expected/myappmetric/metrics.go @@ -13,29 +13,50 @@ import ( "example.com/semconv/semconvmeter" ) -// TaskDurationHistogram is `myapp.task.duration`. +// TaskDuration is `myapp.task.duration`. // // Time a task took from start to finish. -type TaskDurationHistogram struct{ inst metric.Float64Histogram } +type TaskDuration struct{ inst metric.Float64Histogram } -// NewTaskDurationHistogram creates the `myapp.task.duration` instrument from -// meter. -func NewTaskDurationHistogram(meter semconvmeter.Meter) (TaskDurationHistogram, error) { +// NewTaskDuration creates the `myapp.task.duration` instrument from meter. +func NewTaskDuration(meter semconvmeter.Meter) (TaskDuration, error) { + var m TaskDuration inst, err := meter.MetricMeter().Float64Histogram( - "myapp.task.duration", - metric.WithDescription("Time a task took from start to finish."), - metric.WithUnit("s"), + m.Name(), + metric.WithDescription(m.Description()), + metric.WithUnit(m.Unit()), metric.WithExplicitBucketBoundaries(0.005, 0.01, 0.025, 0.05, 0.075, 0.1, 0.25, 0.5, 0.75, 1, 2.5, 5, 7.5, 10), ) if err != nil { - return TaskDurationHistogram{}, fmt.Errorf("create the %s instrument: %w", "myapp.task.duration", err) + return TaskDuration{}, fmt.Errorf("create the %s instrument: %w", m.Name(), err) } - return TaskDurationHistogram{inst: inst}, nil + return TaskDuration{inst: inst}, nil +} + +// Name returns the name `myapp.task.duration` records under. +func (TaskDuration) Name() string { + return "myapp.task.duration" +} + +// Unit returns the unit of `myapp.task.duration`. +func (TaskDuration) Unit() string { + return "s" +} + +// Description returns the description of `myapp.task.duration`. +func (TaskDuration) Description() string { + return "Time a task took from start to finish." +} + +// Inst returns the underlying metric.Float64Histogram, or nil for the zero +// TaskDuration. +func (m TaskDuration) Inst() metric.Float64Histogram { + return m.inst } // Record records one `myapp.task.duration` measurement. The zero -// TaskDurationHistogram records nothing. -func (m TaskDurationHistogram) Record(ctx context.Context, value float64, myappTaskID myappattr.TaskIDAttr) { +// TaskDuration records nothing. +func (m TaskDuration) Record(ctx context.Context, value float64, myappTaskID myappattr.TaskID) { if m.inst == nil { return } @@ -44,29 +65,50 @@ func (m TaskDurationHistogram) Record(ctx context.Context, value float64, myappT m.inst.Record(ctx, value, metric.WithAttributes(kvs...)) } -// TaskLatencyHistogram is `myapp.task.latency`. +// TaskLatency is `myapp.task.latency`. // // Time between a task being queued and started. -type TaskLatencyHistogram struct{ inst metric.Float64Histogram } +type TaskLatency struct{ inst metric.Float64Histogram } -// NewTaskLatencyHistogram creates the `myapp.task.latency` instrument from -// meter. -func NewTaskLatencyHistogram(meter semconvmeter.Meter) (TaskLatencyHistogram, error) { +// NewTaskLatency creates the `myapp.task.latency` instrument from meter. +func NewTaskLatency(meter semconvmeter.Meter) (TaskLatency, error) { + var m TaskLatency inst, err := meter.MetricMeter().Float64Histogram( - "myapp.task.latency", - metric.WithDescription("Time between a task being queued and started."), - metric.WithUnit("s"), + m.Name(), + metric.WithDescription(m.Description()), + metric.WithUnit(m.Unit()), metric.WithExplicitBucketBoundaries(1, 10, 100), ) if err != nil { - return TaskLatencyHistogram{}, fmt.Errorf("create the %s instrument: %w", "myapp.task.latency", err) + return TaskLatency{}, fmt.Errorf("create the %s instrument: %w", m.Name(), err) } - return TaskLatencyHistogram{inst: inst}, nil + return TaskLatency{inst: inst}, nil +} + +// Name returns the name `myapp.task.latency` records under. +func (TaskLatency) Name() string { + return "myapp.task.latency" +} + +// Unit returns the unit of `myapp.task.latency`. +func (TaskLatency) Unit() string { + return "s" +} + +// Description returns the description of `myapp.task.latency`. +func (TaskLatency) Description() string { + return "Time between a task being queued and started." +} + +// Inst returns the underlying metric.Float64Histogram, or nil for the zero +// TaskLatency. +func (m TaskLatency) Inst() metric.Float64Histogram { + return m.inst } -// Record records one `myapp.task.latency` measurement. The zero -// TaskLatencyHistogram records nothing. -func (m TaskLatencyHistogram) Record(ctx context.Context, value float64, myappTaskID myappattr.TaskIDAttr) { +// Record records one `myapp.task.latency` measurement. The zero TaskLatency +// records nothing. +func (m TaskLatency) Record(ctx context.Context, value float64, myappTaskID myappattr.TaskID) { if m.inst == nil { return } @@ -75,30 +117,52 @@ func (m TaskLatencyHistogram) Record(ctx context.Context, value float64, myappTa m.inst.Record(ctx, value, metric.WithAttributes(kvs...)) } -// TaskRetryDurationHistogram is `myapp.task.retry.duration`, a refinement of +// TaskRetryDuration is `myapp.task.retry.duration`, a refinement of // `myapp.task.duration` that records under that metric's name. // // Time a retried task took from start to finish. -type TaskRetryDurationHistogram struct{ inst metric.Float64Histogram } +type TaskRetryDuration struct{ inst metric.Float64Histogram } -// NewTaskRetryDurationHistogram creates the `myapp.task.duration` instrument -// from meter. -func NewTaskRetryDurationHistogram(meter semconvmeter.Meter) (TaskRetryDurationHistogram, error) { +// NewTaskRetryDuration creates the `myapp.task.duration` instrument from +// meter. +func NewTaskRetryDuration(meter semconvmeter.Meter) (TaskRetryDuration, error) { + var m TaskRetryDuration inst, err := meter.MetricMeter().Float64Histogram( - "myapp.task.duration", - metric.WithDescription("Time a task took from start to finish."), - metric.WithUnit("s"), + m.Name(), + metric.WithDescription(m.Description()), + metric.WithUnit(m.Unit()), metric.WithExplicitBucketBoundaries(0.005, 0.01, 0.025, 0.05, 0.075, 0.1, 0.25, 0.5, 0.75, 1, 2.5, 5, 7.5, 10), ) if err != nil { - return TaskRetryDurationHistogram{}, fmt.Errorf("create the %s instrument: %w", "myapp.task.duration", err) + return TaskRetryDuration{}, fmt.Errorf("create the %s instrument: %w", m.Name(), err) } - return TaskRetryDurationHistogram{inst: inst}, nil + return TaskRetryDuration{inst: inst}, nil +} + +// Name returns the name `myapp.task.retry.duration` records under. +func (TaskRetryDuration) Name() string { + return "myapp.task.duration" +} + +// Unit returns the unit of `myapp.task.retry.duration`. +func (TaskRetryDuration) Unit() string { + return "s" +} + +// Description returns the description of `myapp.task.retry.duration`. +func (TaskRetryDuration) Description() string { + return "Time a task took from start to finish." +} + +// Inst returns the underlying metric.Float64Histogram, or nil for the zero +// TaskRetryDuration. +func (m TaskRetryDuration) Inst() metric.Float64Histogram { + return m.inst } // Record records one `myapp.task.retry.duration` measurement. The zero -// TaskRetryDurationHistogram records nothing. -func (m TaskRetryDurationHistogram) Record(ctx context.Context, value float64, myappTaskID myappattr.TaskIDAttr) { +// TaskRetryDuration records nothing. +func (m TaskRetryDuration) Record(ctx context.Context, value float64, myappTaskID myappattr.TaskID) { if m.inst == nil { return } @@ -107,27 +171,49 @@ func (m TaskRetryDurationHistogram) Record(ctx context.Context, value float64, m m.inst.Record(ctx, value, metric.WithAttributes(kvs...)) } -// TaskSizeHistogram is `myapp.task.size`. +// TaskSize is `myapp.task.size`. // // Size of a task's payload. -type TaskSizeHistogram struct{ inst metric.Float64Histogram } +type TaskSize struct{ inst metric.Float64Histogram } -// NewTaskSizeHistogram creates the `myapp.task.size` instrument from meter. -func NewTaskSizeHistogram(meter semconvmeter.Meter) (TaskSizeHistogram, error) { +// NewTaskSize creates the `myapp.task.size` instrument from meter. +func NewTaskSize(meter semconvmeter.Meter) (TaskSize, error) { + var m TaskSize inst, err := meter.MetricMeter().Float64Histogram( - "myapp.task.size", - metric.WithDescription("Size of a task\u0027s payload."), - metric.WithUnit("By"), + m.Name(), + metric.WithDescription(m.Description()), + metric.WithUnit(m.Unit()), ) if err != nil { - return TaskSizeHistogram{}, fmt.Errorf("create the %s instrument: %w", "myapp.task.size", err) + return TaskSize{}, fmt.Errorf("create the %s instrument: %w", m.Name(), err) } - return TaskSizeHistogram{inst: inst}, nil + return TaskSize{inst: inst}, nil +} + +// Name returns the name `myapp.task.size` records under. +func (TaskSize) Name() string { + return "myapp.task.size" +} + +// Unit returns the unit of `myapp.task.size`. +func (TaskSize) Unit() string { + return "By" +} + +// Description returns the description of `myapp.task.size`. +func (TaskSize) Description() string { + return "Size of a task\u0027s payload." +} + +// Inst returns the underlying metric.Float64Histogram, or nil for the zero +// TaskSize. +func (m TaskSize) Inst() metric.Float64Histogram { + return m.inst } -// Record records one `myapp.task.size` measurement. The zero -// TaskSizeHistogram records nothing. -func (m TaskSizeHistogram) Record(ctx context.Context, value float64, myappTaskID myappattr.TaskIDAttr) { +// Record records one `myapp.task.size` measurement. The zero TaskSize +// records nothing. +func (m TaskSize) Record(ctx context.Context, value float64, myappTaskID myappattr.TaskID) { if m.inst == nil { return } diff --git a/templates/code/go/tests/histogram_boundaries_by_unit_params/expected/myappattr/attributes.go b/templates/code/go/tests/histogram_boundaries_by_unit_params/expected/myappattr/attributes.go index 2e0bf1d..d20b02e 100644 --- a/templates/code/go/tests/histogram_boundaries_by_unit_params/expected/myappattr/attributes.go +++ b/templates/code/go/tests/histogram_boundaries_by_unit_params/expected/myappattr/attributes.go @@ -7,22 +7,22 @@ import "go.opentelemetry.io/otel/attribute" // taskIDKey is the attribute key of `myapp.task.id`. const taskIDKey = attribute.Key("myapp.task.id") -// TaskIDAttr is a value of `myapp.task.id`. +// TaskID is a value of `myapp.task.id`. // // Unique identifier of the task. -type TaskIDAttr struct{ value string } +type TaskID struct{ value string } -// NewTaskIDAttr returns a value of `myapp.task.id`. -func NewTaskIDAttr(value string) TaskIDAttr { - return TaskIDAttr{value: value} +// NewTaskID returns a value of `myapp.task.id`. +func NewTaskID(value string) TaskID { + return TaskID{value: value} } // Key is the attribute key, for filters and views that need it. -func (TaskIDAttr) Key() attribute.Key { +func (TaskID) Key() attribute.Key { return taskIDKey } // KeyValue is the `myapp.task.id` attribute set to this value. -func (v TaskIDAttr) KeyValue() attribute.KeyValue { +func (v TaskID) KeyValue() attribute.KeyValue { return taskIDKey.String(v.value) } diff --git a/templates/code/go/tests/histogram_boundaries_by_unit_params/expected/myappmetric/metrics.go b/templates/code/go/tests/histogram_boundaries_by_unit_params/expected/myappmetric/metrics.go index 6d28300..d931174 100644 --- a/templates/code/go/tests/histogram_boundaries_by_unit_params/expected/myappmetric/metrics.go +++ b/templates/code/go/tests/histogram_boundaries_by_unit_params/expected/myappmetric/metrics.go @@ -13,28 +13,49 @@ import ( "example.com/semconv/semconvmeter" ) -// TaskDurationHistogram is `myapp.task.duration`. +// TaskDuration is `myapp.task.duration`. // // Time a task took from start to finish. -type TaskDurationHistogram struct{ inst metric.Float64Histogram } +type TaskDuration struct{ inst metric.Float64Histogram } -// NewTaskDurationHistogram creates the `myapp.task.duration` instrument from -// meter. -func NewTaskDurationHistogram(meter semconvmeter.Meter) (TaskDurationHistogram, error) { +// NewTaskDuration creates the `myapp.task.duration` instrument from meter. +func NewTaskDuration(meter semconvmeter.Meter) (TaskDuration, error) { + var m TaskDuration inst, err := meter.MetricMeter().Float64Histogram( - "myapp.task.duration", - metric.WithDescription("Time a task took from start to finish."), - metric.WithUnit("s"), + m.Name(), + metric.WithDescription(m.Description()), + metric.WithUnit(m.Unit()), ) if err != nil { - return TaskDurationHistogram{}, fmt.Errorf("create the %s instrument: %w", "myapp.task.duration", err) + return TaskDuration{}, fmt.Errorf("create the %s instrument: %w", m.Name(), err) } - return TaskDurationHistogram{inst: inst}, nil + return TaskDuration{inst: inst}, nil +} + +// Name returns the name `myapp.task.duration` records under. +func (TaskDuration) Name() string { + return "myapp.task.duration" +} + +// Unit returns the unit of `myapp.task.duration`. +func (TaskDuration) Unit() string { + return "s" +} + +// Description returns the description of `myapp.task.duration`. +func (TaskDuration) Description() string { + return "Time a task took from start to finish." +} + +// Inst returns the underlying metric.Float64Histogram, or nil for the zero +// TaskDuration. +func (m TaskDuration) Inst() metric.Float64Histogram { + return m.inst } // Record records one `myapp.task.duration` measurement. The zero -// TaskDurationHistogram records nothing. -func (m TaskDurationHistogram) Record(ctx context.Context, value float64, myappTaskID myappattr.TaskIDAttr) { +// TaskDuration records nothing. +func (m TaskDuration) Record(ctx context.Context, value float64, myappTaskID myappattr.TaskID) { if m.inst == nil { return } @@ -43,29 +64,51 @@ func (m TaskDurationHistogram) Record(ctx context.Context, value float64, myappT m.inst.Record(ctx, value, metric.WithAttributes(kvs...)) } -// TaskQueueWaitHistogram is `myapp.task.queue_wait`. +// TaskQueueWait is `myapp.task.queue_wait`. // // Time a task waited in the queue, in minutes. -type TaskQueueWaitHistogram struct{ inst metric.Float64Histogram } +type TaskQueueWait struct{ inst metric.Float64Histogram } -// NewTaskQueueWaitHistogram creates the `myapp.task.queue_wait` instrument -// from meter. -func NewTaskQueueWaitHistogram(meter semconvmeter.Meter) (TaskQueueWaitHistogram, error) { +// NewTaskQueueWait creates the `myapp.task.queue_wait` instrument from +// meter. +func NewTaskQueueWait(meter semconvmeter.Meter) (TaskQueueWait, error) { + var m TaskQueueWait inst, err := meter.MetricMeter().Float64Histogram( - "myapp.task.queue_wait", - metric.WithDescription("Time a task waited in the queue, in minutes."), - metric.WithUnit("min"), + m.Name(), + metric.WithDescription(m.Description()), + metric.WithUnit(m.Unit()), metric.WithExplicitBucketBoundaries(1, 5, 10, 30, 60), ) if err != nil { - return TaskQueueWaitHistogram{}, fmt.Errorf("create the %s instrument: %w", "myapp.task.queue_wait", err) + return TaskQueueWait{}, fmt.Errorf("create the %s instrument: %w", m.Name(), err) } - return TaskQueueWaitHistogram{inst: inst}, nil + return TaskQueueWait{inst: inst}, nil +} + +// Name returns the name `myapp.task.queue_wait` records under. +func (TaskQueueWait) Name() string { + return "myapp.task.queue_wait" +} + +// Unit returns the unit of `myapp.task.queue_wait`. +func (TaskQueueWait) Unit() string { + return "min" +} + +// Description returns the description of `myapp.task.queue_wait`. +func (TaskQueueWait) Description() string { + return "Time a task waited in the queue, in minutes." +} + +// Inst returns the underlying metric.Float64Histogram, or nil for the zero +// TaskQueueWait. +func (m TaskQueueWait) Inst() metric.Float64Histogram { + return m.inst } // Record records one `myapp.task.queue_wait` measurement. The zero -// TaskQueueWaitHistogram records nothing. -func (m TaskQueueWaitHistogram) Record(ctx context.Context, value float64, myappTaskID myappattr.TaskIDAttr) { +// TaskQueueWait records nothing. +func (m TaskQueueWait) Record(ctx context.Context, value float64, myappTaskID myappattr.TaskID) { if m.inst == nil { return } diff --git a/templates/code/go/tests/imported/expected/edgemetric/metrics.go b/templates/code/go/tests/imported/expected/edgemetric/metrics.go index b710b68..c4d5ff0 100644 --- a/templates/code/go/tests/imported/expected/edgemetric/metrics.go +++ b/templates/code/go/tests/imported/expected/edgemetric/metrics.go @@ -12,54 +12,75 @@ import ( "example.com/semconv/semconvmeter" ) -// UpstreamDurationHistogramAttr is an attribute `edge.upstream.duration` -// accepts in addition to the ones UpstreamDurationHistogram.Record requires. -type UpstreamDurationHistogramAttr interface { - upstreamDurationHistogramAttr() attribute.KeyValue +// UpstreamDurationAttr is an attribute `edge.upstream.duration` accepts in +// addition to the ones UpstreamDuration.Record requires. +type UpstreamDurationAttr interface { + upstreamDurationAttr() attribute.KeyValue } -type upstreamDurationHistogramServerPort struct{ v int } +type upstreamDurationServerPort struct{ v int } -func (o upstreamDurationHistogramServerPort) upstreamDurationHistogramAttr() attribute.KeyValue { +func (o upstreamDurationServerPort) upstreamDurationAttr() attribute.KeyValue { return attribute.Int("server.port", o.v) } -// WithUpstreamDurationHistogramServerPort attaches `server.port` to -// UpstreamDurationHistogram. -func WithUpstreamDurationHistogramServerPort(v int) UpstreamDurationHistogramAttr { - return upstreamDurationHistogramServerPort{v: v} +// WithUpstreamDurationServerPort attaches `server.port` to UpstreamDuration. +func WithUpstreamDurationServerPort(v int) UpstreamDurationAttr { + return upstreamDurationServerPort{v: v} } -// UpstreamDurationHistogram is `edge.upstream.duration`. +// UpstreamDuration is `edge.upstream.duration`. // // Time spent waiting on an upstream server. -type UpstreamDurationHistogram struct{ inst metric.Float64Histogram } +type UpstreamDuration struct{ inst metric.Float64Histogram } -// NewUpstreamDurationHistogram creates the `edge.upstream.duration` -// instrument from meter. -func NewUpstreamDurationHistogram(meter semconvmeter.Meter) (UpstreamDurationHistogram, error) { +// NewUpstreamDuration creates the `edge.upstream.duration` instrument from +// meter. +func NewUpstreamDuration(meter semconvmeter.Meter) (UpstreamDuration, error) { + var m UpstreamDuration inst, err := meter.MetricMeter().Float64Histogram( - "edge.upstream.duration", - metric.WithDescription("Time spent waiting on an upstream server."), - metric.WithUnit("s"), + m.Name(), + metric.WithDescription(m.Description()), + metric.WithUnit(m.Unit()), metric.WithExplicitBucketBoundaries(0.005, 0.01, 0.025, 0.05, 0.075, 0.1, 0.25, 0.5, 0.75, 1, 2.5, 5, 7.5, 10), ) if err != nil { - return UpstreamDurationHistogram{}, fmt.Errorf("create the %s instrument: %w", "edge.upstream.duration", err) + return UpstreamDuration{}, fmt.Errorf("create the %s instrument: %w", m.Name(), err) } - return UpstreamDurationHistogram{inst: inst}, nil + return UpstreamDuration{inst: inst}, nil +} + +// Name returns the name `edge.upstream.duration` records under. +func (UpstreamDuration) Name() string { + return "edge.upstream.duration" +} + +// Unit returns the unit of `edge.upstream.duration`. +func (UpstreamDuration) Unit() string { + return "s" +} + +// Description returns the description of `edge.upstream.duration`. +func (UpstreamDuration) Description() string { + return "Time spent waiting on an upstream server." +} + +// Inst returns the underlying metric.Float64Histogram, or nil for the zero +// UpstreamDuration. +func (m UpstreamDuration) Inst() metric.Float64Histogram { + return m.inst } // Record records one `edge.upstream.duration` measurement. The zero -// UpstreamDurationHistogram records nothing. -func (m UpstreamDurationHistogram) Record(ctx context.Context, value float64, serverAddress string, opts ...UpstreamDurationHistogramAttr) { +// UpstreamDuration records nothing. +func (m UpstreamDuration) Record(ctx context.Context, value float64, serverAddress string, opts ...UpstreamDurationAttr) { if m.inst == nil { return } kvs := make([]attribute.KeyValue, 0, 1+len(opts)) kvs = append(kvs, attribute.String("server.address", serverAddress)) for _, opt := range opts { - kvs = append(kvs, opt.upstreamDurationHistogramAttr()) + kvs = append(kvs, opt.upstreamDurationAttr()) } m.inst.Record(ctx, value, metric.WithAttributes(kvs...)) } diff --git a/templates/code/go/tests/imported/expected/edgespan/spans.go b/templates/code/go/tests/imported/expected/edgespan/spans.go index db527cf..31e2325 100644 --- a/templates/code/go/tests/imported/expected/edgespan/spans.go +++ b/templates/code/go/tests/imported/expected/edgespan/spans.go @@ -19,8 +19,8 @@ type UpstreamRequestStartAttr interface { upstreamRequestStartAttr() attribute.KeyValue } -// UpstreamRequestAttr is an attribute a UpstreamRequestSpan also accepts -// after it started, through SetAttributes. +// UpstreamRequestAttr is an attribute a UpstreamRequest also accepts after +// it started, through SetAttributes. type UpstreamRequestAttr interface { UpstreamRequestStartAttr upstreamRequestAttr() @@ -49,19 +49,19 @@ func (o upstreamRequestSpanHTTPRequestMethodList) upstreamRequestStartAttr() att func (upstreamRequestSpanHTTPRequestMethodList) upstreamRequestAttr() {} // WithUpstreamRequestHTTPRequestMethodList sets `http.request.method_list` -// on a UpstreamRequestSpan, when StartUpstreamRequest starts it or later -// through SetAttributes. +// on a UpstreamRequest, when StartUpstreamRequest starts it or later through +// SetAttributes. func WithUpstreamRequestHTTPRequestMethodList(v []string) UpstreamRequestAttr { return upstreamRequestSpanHTTPRequestMethodList{v: v} } -// UpstreamRequestSpan is a started span of `edge.upstream.request`. The zero -// UpstreamRequestSpan records nothing. -type UpstreamRequestSpan struct{ span trace.Span } +// UpstreamRequest is a started span of `edge.upstream.request`. The zero +// UpstreamRequest records nothing. +type UpstreamRequest struct{ span trace.Span } // Span returns the underlying trace.Span, or a no-op one for the zero -// UpstreamRequestSpan. -func (s UpstreamRequestSpan) Span() trace.Span { +// UpstreamRequest. +func (s UpstreamRequest) Span() trace.Span { if s.span == nil { return noop.Span{} } @@ -69,12 +69,12 @@ func (s UpstreamRequestSpan) Span() trace.Span { } // End ends the span. -func (s UpstreamRequestSpan) End(opts ...trace.SpanEndOption) { +func (s UpstreamRequest) End(opts ...trace.SpanEndOption) { s.Span().End(opts...) } // SetAttributes sets attributes on the span after it started. -func (s UpstreamRequestSpan) SetAttributes(attrs ...UpstreamRequestAttr) { +func (s UpstreamRequest) SetAttributes(attrs ...UpstreamRequestAttr) { kvs := make([]attribute.KeyValue, 0, len(attrs)) for _, attr := range attrs { kvs = append(kvs, attr.upstreamRequestStartAttr()) @@ -83,12 +83,12 @@ func (s UpstreamRequestSpan) SetAttributes(attrs ...UpstreamRequestAttr) { } // RecordError records err as an exception event on the span. -func (s UpstreamRequestSpan) RecordError(err error, opts ...trace.EventOption) { +func (s UpstreamRequest) RecordError(err error, opts ...trace.EventOption) { s.Span().RecordError(err, opts...) } // SetStatus sets the status of the span. -func (s UpstreamRequestSpan) SetStatus(code codes.Code, description string) { +func (s UpstreamRequest) SetStatus(code codes.Code, description string) { s.Span().SetStatus(code, description) } @@ -99,7 +99,7 @@ func (s UpstreamRequestSpan) SetStatus(code codes.Code, description string) { // // The span is named `{server.address}:{server.port}`, with each placeholder // replaced by the value of the attribute it names. -func StartUpstreamRequest(ctx context.Context, tracer semconvtracer.Tracer, serverAddress string, serverPort int, opts ...UpstreamRequestStartAttr) (context.Context, UpstreamRequestSpan) { +func StartUpstreamRequest(ctx context.Context, tracer semconvtracer.Tracer, serverAddress string, serverPort int, opts ...UpstreamRequestStartAttr) (context.Context, UpstreamRequest) { kvs := make([]attribute.KeyValue, 0, 2+len(opts)) kvs = append(kvs, attribute.String("server.address", serverAddress)) kvs = append(kvs, attribute.Int("server.port", serverPort)) @@ -113,5 +113,5 @@ func StartUpstreamRequest(ctx context.Context, tracer semconvtracer.Tracer, serv trace.WithSpanKind(trace.SpanKindClient), trace.WithAttributes(kvs...), ) - return ctx, UpstreamRequestSpan{span: span} + return ctx, UpstreamRequest{span: span} } diff --git a/templates/code/go/tests/imported/expected/myappattr/attributes.go b/templates/code/go/tests/imported/expected/myappattr/attributes.go index 2e0bf1d..d20b02e 100644 --- a/templates/code/go/tests/imported/expected/myappattr/attributes.go +++ b/templates/code/go/tests/imported/expected/myappattr/attributes.go @@ -7,22 +7,22 @@ import "go.opentelemetry.io/otel/attribute" // taskIDKey is the attribute key of `myapp.task.id`. const taskIDKey = attribute.Key("myapp.task.id") -// TaskIDAttr is a value of `myapp.task.id`. +// TaskID is a value of `myapp.task.id`. // // Unique identifier of the task. -type TaskIDAttr struct{ value string } +type TaskID struct{ value string } -// NewTaskIDAttr returns a value of `myapp.task.id`. -func NewTaskIDAttr(value string) TaskIDAttr { - return TaskIDAttr{value: value} +// NewTaskID returns a value of `myapp.task.id`. +func NewTaskID(value string) TaskID { + return TaskID{value: value} } // Key is the attribute key, for filters and views that need it. -func (TaskIDAttr) Key() attribute.Key { +func (TaskID) Key() attribute.Key { return taskIDKey } // KeyValue is the `myapp.task.id` attribute set to this value. -func (v TaskIDAttr) KeyValue() attribute.KeyValue { +func (v TaskID) KeyValue() attribute.KeyValue { return taskIDKey.String(v.value) } diff --git a/templates/code/go/tests/imported/expected/myappmetric/metrics.go b/templates/code/go/tests/imported/expected/myappmetric/metrics.go index d895c37..dd399db 100644 --- a/templates/code/go/tests/imported/expected/myappmetric/metrics.go +++ b/templates/code/go/tests/imported/expected/myappmetric/metrics.go @@ -13,46 +13,67 @@ import ( "example.com/semconv/semconvmeter" ) -// TaskFailedCounterAttr is an attribute `myapp.task.failed` accepts in -// addition to the ones TaskFailedCounter.Add requires. -type TaskFailedCounterAttr interface { - taskFailedCounterAttr() attribute.KeyValue +// TaskFailedAttr is an attribute `myapp.task.failed` accepts in addition to +// the ones TaskFailed.Add requires. +type TaskFailedAttr interface { + taskFailedAttr() attribute.KeyValue } -type taskFailedCounterHTTPRequestMethodList struct{ v []string } +type taskFailedHTTPRequestMethodList struct{ v []string } -func (o taskFailedCounterHTTPRequestMethodList) taskFailedCounterAttr() attribute.KeyValue { +func (o taskFailedHTTPRequestMethodList) taskFailedAttr() attribute.KeyValue { return attribute.StringSlice("http.request.method_list", o.v) } -// WithTaskFailedCounterHTTPRequestMethodList attaches -// `http.request.method_list` to TaskFailedCounter. -func WithTaskFailedCounterHTTPRequestMethodList(v []string) TaskFailedCounterAttr { - return taskFailedCounterHTTPRequestMethodList{v: v} +// WithTaskFailedHTTPRequestMethodList attaches `http.request.method_list` to +// TaskFailed. +func WithTaskFailedHTTPRequestMethodList(v []string) TaskFailedAttr { + return taskFailedHTTPRequestMethodList{v: v} } -// TaskFailedCounter is `myapp.task.failed`. +// TaskFailed is `myapp.task.failed`. // // Number of tasks that failed. -type TaskFailedCounter struct{ inst metric.Int64Counter } +type TaskFailed struct{ inst metric.Int64Counter } -// NewTaskFailedCounter creates the `myapp.task.failed` instrument from -// meter. -func NewTaskFailedCounter(meter semconvmeter.Meter) (TaskFailedCounter, error) { +// NewTaskFailed creates the `myapp.task.failed` instrument from meter. +func NewTaskFailed(meter semconvmeter.Meter) (TaskFailed, error) { + var m TaskFailed inst, err := meter.MetricMeter().Int64Counter( - "myapp.task.failed", - metric.WithDescription("Number of tasks that failed."), - metric.WithUnit("{task}"), + m.Name(), + metric.WithDescription(m.Description()), + metric.WithUnit(m.Unit()), ) if err != nil { - return TaskFailedCounter{}, fmt.Errorf("create the %s instrument: %w", "myapp.task.failed", err) + return TaskFailed{}, fmt.Errorf("create the %s instrument: %w", m.Name(), err) } - return TaskFailedCounter{inst: inst}, nil + return TaskFailed{inst: inst}, nil } -// Add records one `myapp.task.failed` measurement. The zero -// TaskFailedCounter records nothing. -func (m TaskFailedCounter) Add(ctx context.Context, incr int64, errorType string, myappTaskID myappattr.TaskIDAttr, opts ...TaskFailedCounterAttr) { +// Name returns the name `myapp.task.failed` records under. +func (TaskFailed) Name() string { + return "myapp.task.failed" +} + +// Unit returns the unit of `myapp.task.failed`. +func (TaskFailed) Unit() string { + return "{task}" +} + +// Description returns the description of `myapp.task.failed`. +func (TaskFailed) Description() string { + return "Number of tasks that failed." +} + +// Inst returns the underlying metric.Int64Counter, or nil for the zero +// TaskFailed. +func (m TaskFailed) Inst() metric.Int64Counter { + return m.inst +} + +// Add records one `myapp.task.failed` measurement. The zero TaskFailed +// records nothing. +func (m TaskFailed) Add(ctx context.Context, incr int64, errorType string, myappTaskID myappattr.TaskID, opts ...TaskFailedAttr) { if m.inst == nil { return } @@ -60,20 +81,20 @@ func (m TaskFailedCounter) Add(ctx context.Context, incr int64, errorType string kvs = append(kvs, attribute.String("error.type", errorType)) kvs = append(kvs, myappTaskID.KeyValue()) for _, opt := range opts { - kvs = append(kvs, opt.taskFailedCounterAttr()) + kvs = append(kvs, opt.taskFailedAttr()) } m.inst.Add(ctx, incr, metric.WithAttributes(kvs...)) } -// TaskFailedCounterObserver records `myapp.task.failed` observations from -// the callback of a TaskFailedObservableCounter. The zero -// TaskFailedCounterObserver records nothing. -type TaskFailedCounterObserver struct { +// TaskFailedObserver records `myapp.task.failed` observations from the +// callback of a TaskFailedObservable. The zero TaskFailedObserver records +// nothing. +type TaskFailedObserver struct { o metric.Int64Observer } // Observe records one `myapp.task.failed` observation. -func (o TaskFailedCounterObserver) Observe(value int64, errorType string, myappTaskID myappattr.TaskIDAttr, opts ...TaskFailedCounterAttr) { +func (o TaskFailedObserver) Observe(value int64, errorType string, myappTaskID myappattr.TaskID, opts ...TaskFailedAttr) { if o.o == nil { return } @@ -81,40 +102,62 @@ func (o TaskFailedCounterObserver) Observe(value int64, errorType string, myappT kvs = append(kvs, attribute.String("error.type", errorType)) kvs = append(kvs, myappTaskID.KeyValue()) for _, opt := range opts { - kvs = append(kvs, opt.taskFailedCounterAttr()) + kvs = append(kvs, opt.taskFailedAttr()) } o.o.Observe(value, metric.WithAttributes(kvs...)) } -// TaskFailedCounterCallback observes `myapp.task.failed` through o on every -// collection of a TaskFailedObservableCounter. +// TaskFailedCallback observes `myapp.task.failed` through o on every +// collection of a TaskFailedObservable. // // An error it returns is returned by the collection that ran it, and the // observations made before it returned are still recorded. -type TaskFailedCounterCallback func(ctx context.Context, o TaskFailedCounterObserver) error +type TaskFailedCallback func(ctx context.Context, o TaskFailedObserver) error -// TaskFailedObservableCounter is the asynchronous form of TaskFailedCounter, -// observed through the callback it was created with. -type TaskFailedObservableCounter struct { +// TaskFailedObservable is the asynchronous form of TaskFailed, observed +// through the callback it was created with. +type TaskFailedObservable struct { inst metric.Int64ObservableCounter } -// NewTaskFailedObservableCounter creates the `myapp.task.failed` instrument -// from meter and registers callback to observe it on every collection. -func NewTaskFailedObservableCounter(meter semconvmeter.Meter, callback TaskFailedCounterCallback) (TaskFailedObservableCounter, error) { +// NewTaskFailedObservable creates the `myapp.task.failed` instrument from +// meter and registers callback to observe it on every collection. +func NewTaskFailedObservable(meter semconvmeter.Meter, callback TaskFailedCallback) (TaskFailedObservable, error) { + var m TaskFailedObservable if callback == nil { - return TaskFailedObservableCounter{}, fmt.Errorf("create the %s instrument: the callback is nil", "myapp.task.failed") + return TaskFailedObservable{}, fmt.Errorf("create the %s instrument: the callback is nil", m.Name()) } inst, err := meter.MetricMeter().Int64ObservableCounter( - "myapp.task.failed", - metric.WithDescription("Number of tasks that failed."), - metric.WithUnit("{task}"), + m.Name(), + metric.WithDescription(m.Description()), + metric.WithUnit(m.Unit()), metric.WithInt64Callback(func(ctx context.Context, o metric.Int64Observer) error { - return callback(ctx, TaskFailedCounterObserver{o: o}) + return callback(ctx, TaskFailedObserver{o: o}) }), ) if err != nil { - return TaskFailedObservableCounter{}, fmt.Errorf("create the %s instrument: %w", "myapp.task.failed", err) + return TaskFailedObservable{}, fmt.Errorf("create the %s instrument: %w", m.Name(), err) } - return TaskFailedObservableCounter{inst: inst}, nil + return TaskFailedObservable{inst: inst}, nil +} + +// Name returns the name `myapp.task.failed` records under. +func (TaskFailedObservable) Name() string { + return TaskFailed{}.Name() +} + +// Unit returns the unit of `myapp.task.failed`. +func (TaskFailedObservable) Unit() string { + return TaskFailed{}.Unit() +} + +// Description returns the description of `myapp.task.failed`. +func (TaskFailedObservable) Description() string { + return TaskFailed{}.Description() +} + +// Inst returns the underlying metric.Int64ObservableCounter, or nil for the +// zero TaskFailedObservable. +func (m TaskFailedObservable) Inst() metric.Int64ObservableCounter { + return m.inst } diff --git a/templates/code/go/tests/imported_typed/expected/myappattr/attributes.go b/templates/code/go/tests/imported_typed/expected/myappattr/attributes.go index 2e0bf1d..d20b02e 100644 --- a/templates/code/go/tests/imported_typed/expected/myappattr/attributes.go +++ b/templates/code/go/tests/imported_typed/expected/myappattr/attributes.go @@ -7,22 +7,22 @@ import "go.opentelemetry.io/otel/attribute" // taskIDKey is the attribute key of `myapp.task.id`. const taskIDKey = attribute.Key("myapp.task.id") -// TaskIDAttr is a value of `myapp.task.id`. +// TaskID is a value of `myapp.task.id`. // // Unique identifier of the task. -type TaskIDAttr struct{ value string } +type TaskID struct{ value string } -// NewTaskIDAttr returns a value of `myapp.task.id`. -func NewTaskIDAttr(value string) TaskIDAttr { - return TaskIDAttr{value: value} +// NewTaskID returns a value of `myapp.task.id`. +func NewTaskID(value string) TaskID { + return TaskID{value: value} } // Key is the attribute key, for filters and views that need it. -func (TaskIDAttr) Key() attribute.Key { +func (TaskID) Key() attribute.Key { return taskIDKey } // KeyValue is the `myapp.task.id` attribute set to this value. -func (v TaskIDAttr) KeyValue() attribute.KeyValue { +func (v TaskID) KeyValue() attribute.KeyValue { return taskIDKey.String(v.value) } diff --git a/templates/code/go/tests/imported_typed/expected/myappevent/events.go b/templates/code/go/tests/imported_typed/expected/myappevent/events.go index 590ce69..163e72c 100644 --- a/templates/code/go/tests/imported_typed/expected/myappevent/events.go +++ b/templates/code/go/tests/imported_typed/expected/myappevent/events.go @@ -59,7 +59,7 @@ func WithTaskErroredServerPort(v int) TaskErroredOption { // nothing. // // A task failed with an error. -func EmitTaskErrored(ctx context.Context, logger myapplogger.Logger, errorType errorattr.TypeAttr, opts ...TaskErroredOption) { +func EmitTaskErrored(ctx context.Context, logger myapplogger.Logger, errorType errorattr.Type, opts ...TaskErroredOption) { var record log.Record record.SetEventName("myapp.task.errored") record.SetSeverity(log.SeverityInfo) diff --git a/templates/code/go/tests/imported_typed/expected/myappmetric/metrics.go b/templates/code/go/tests/imported_typed/expected/myappmetric/metrics.go index f55266a..d4b249f 100644 --- a/templates/code/go/tests/imported_typed/expected/myappmetric/metrics.go +++ b/templates/code/go/tests/imported_typed/expected/myappmetric/metrics.go @@ -14,46 +14,66 @@ import ( "example.com/upstream/errorattr" ) -// TaskFailedCounterAttr is an attribute `myapp.task.failed` accepts in -// addition to the ones TaskFailedCounter.Add requires. -type TaskFailedCounterAttr interface { - taskFailedCounterAttr() attribute.KeyValue +// TaskFailedAttr is an attribute `myapp.task.failed` accepts in addition to +// the ones TaskFailed.Add requires. +type TaskFailedAttr interface { + taskFailedAttr() attribute.KeyValue } -type taskFailedCounterServerPort struct{ v int } +type taskFailedServerPort struct{ v int } -func (o taskFailedCounterServerPort) taskFailedCounterAttr() attribute.KeyValue { +func (o taskFailedServerPort) taskFailedAttr() attribute.KeyValue { return attribute.Int("server.port", o.v) } -// WithTaskFailedCounterServerPort attaches `server.port` to -// TaskFailedCounter. -func WithTaskFailedCounterServerPort(v int) TaskFailedCounterAttr { - return taskFailedCounterServerPort{v: v} +// WithTaskFailedServerPort attaches `server.port` to TaskFailed. +func WithTaskFailedServerPort(v int) TaskFailedAttr { + return taskFailedServerPort{v: v} } -// TaskFailedCounter is `myapp.task.failed`. +// TaskFailed is `myapp.task.failed`. // // Number of tasks that failed. -type TaskFailedCounter struct{ inst metric.Int64Counter } +type TaskFailed struct{ inst metric.Int64Counter } -// NewTaskFailedCounter creates the `myapp.task.failed` instrument from -// meter. -func NewTaskFailedCounter(meter myappmeter.Meter) (TaskFailedCounter, error) { +// NewTaskFailed creates the `myapp.task.failed` instrument from meter. +func NewTaskFailed(meter myappmeter.Meter) (TaskFailed, error) { + var m TaskFailed inst, err := meter.MetricMeter().Int64Counter( - "myapp.task.failed", - metric.WithDescription("Number of tasks that failed."), - metric.WithUnit("{task}"), + m.Name(), + metric.WithDescription(m.Description()), + metric.WithUnit(m.Unit()), ) if err != nil { - return TaskFailedCounter{}, fmt.Errorf("create the %s instrument: %w", "myapp.task.failed", err) + return TaskFailed{}, fmt.Errorf("create the %s instrument: %w", m.Name(), err) } - return TaskFailedCounter{inst: inst}, nil + return TaskFailed{inst: inst}, nil } -// Add records one `myapp.task.failed` measurement. The zero -// TaskFailedCounter records nothing. -func (m TaskFailedCounter) Add(ctx context.Context, incr int64, errorType errorattr.TypeAttr, myappTaskID myappattr.TaskIDAttr, opts ...TaskFailedCounterAttr) { +// Name returns the name `myapp.task.failed` records under. +func (TaskFailed) Name() string { + return "myapp.task.failed" +} + +// Unit returns the unit of `myapp.task.failed`. +func (TaskFailed) Unit() string { + return "{task}" +} + +// Description returns the description of `myapp.task.failed`. +func (TaskFailed) Description() string { + return "Number of tasks that failed." +} + +// Inst returns the underlying metric.Int64Counter, or nil for the zero +// TaskFailed. +func (m TaskFailed) Inst() metric.Int64Counter { + return m.inst +} + +// Add records one `myapp.task.failed` measurement. The zero TaskFailed +// records nothing. +func (m TaskFailed) Add(ctx context.Context, incr int64, errorType errorattr.Type, myappTaskID myappattr.TaskID, opts ...TaskFailedAttr) { if m.inst == nil { return } @@ -61,20 +81,20 @@ func (m TaskFailedCounter) Add(ctx context.Context, incr int64, errorType errora kvs = append(kvs, errorType.KeyValue()) kvs = append(kvs, myappTaskID.KeyValue()) for _, opt := range opts { - kvs = append(kvs, opt.taskFailedCounterAttr()) + kvs = append(kvs, opt.taskFailedAttr()) } m.inst.Add(ctx, incr, metric.WithAttributes(kvs...)) } -// TaskFailedCounterObserver records `myapp.task.failed` observations from -// the callback of a TaskFailedObservableCounter. The zero -// TaskFailedCounterObserver records nothing. -type TaskFailedCounterObserver struct { +// TaskFailedObserver records `myapp.task.failed` observations from the +// callback of a TaskFailedObservable. The zero TaskFailedObserver records +// nothing. +type TaskFailedObserver struct { o metric.Int64Observer } // Observe records one `myapp.task.failed` observation. -func (o TaskFailedCounterObserver) Observe(value int64, errorType errorattr.TypeAttr, myappTaskID myappattr.TaskIDAttr, opts ...TaskFailedCounterAttr) { +func (o TaskFailedObserver) Observe(value int64, errorType errorattr.Type, myappTaskID myappattr.TaskID, opts ...TaskFailedAttr) { if o.o == nil { return } @@ -82,40 +102,62 @@ func (o TaskFailedCounterObserver) Observe(value int64, errorType errorattr.Type kvs = append(kvs, errorType.KeyValue()) kvs = append(kvs, myappTaskID.KeyValue()) for _, opt := range opts { - kvs = append(kvs, opt.taskFailedCounterAttr()) + kvs = append(kvs, opt.taskFailedAttr()) } o.o.Observe(value, metric.WithAttributes(kvs...)) } -// TaskFailedCounterCallback observes `myapp.task.failed` through o on every -// collection of a TaskFailedObservableCounter. +// TaskFailedCallback observes `myapp.task.failed` through o on every +// collection of a TaskFailedObservable. // // An error it returns is returned by the collection that ran it, and the // observations made before it returned are still recorded. -type TaskFailedCounterCallback func(ctx context.Context, o TaskFailedCounterObserver) error +type TaskFailedCallback func(ctx context.Context, o TaskFailedObserver) error -// TaskFailedObservableCounter is the asynchronous form of TaskFailedCounter, -// observed through the callback it was created with. -type TaskFailedObservableCounter struct { +// TaskFailedObservable is the asynchronous form of TaskFailed, observed +// through the callback it was created with. +type TaskFailedObservable struct { inst metric.Int64ObservableCounter } -// NewTaskFailedObservableCounter creates the `myapp.task.failed` instrument -// from meter and registers callback to observe it on every collection. -func NewTaskFailedObservableCounter(meter myappmeter.Meter, callback TaskFailedCounterCallback) (TaskFailedObservableCounter, error) { +// NewTaskFailedObservable creates the `myapp.task.failed` instrument from +// meter and registers callback to observe it on every collection. +func NewTaskFailedObservable(meter myappmeter.Meter, callback TaskFailedCallback) (TaskFailedObservable, error) { + var m TaskFailedObservable if callback == nil { - return TaskFailedObservableCounter{}, fmt.Errorf("create the %s instrument: the callback is nil", "myapp.task.failed") + return TaskFailedObservable{}, fmt.Errorf("create the %s instrument: the callback is nil", m.Name()) } inst, err := meter.MetricMeter().Int64ObservableCounter( - "myapp.task.failed", - metric.WithDescription("Number of tasks that failed."), - metric.WithUnit("{task}"), + m.Name(), + metric.WithDescription(m.Description()), + metric.WithUnit(m.Unit()), metric.WithInt64Callback(func(ctx context.Context, o metric.Int64Observer) error { - return callback(ctx, TaskFailedCounterObserver{o: o}) + return callback(ctx, TaskFailedObserver{o: o}) }), ) if err != nil { - return TaskFailedObservableCounter{}, fmt.Errorf("create the %s instrument: %w", "myapp.task.failed", err) + return TaskFailedObservable{}, fmt.Errorf("create the %s instrument: %w", m.Name(), err) } - return TaskFailedObservableCounter{inst: inst}, nil + return TaskFailedObservable{inst: inst}, nil +} + +// Name returns the name `myapp.task.failed` records under. +func (TaskFailedObservable) Name() string { + return TaskFailed{}.Name() +} + +// Unit returns the unit of `myapp.task.failed`. +func (TaskFailedObservable) Unit() string { + return TaskFailed{}.Unit() +} + +// Description returns the description of `myapp.task.failed`. +func (TaskFailedObservable) Description() string { + return TaskFailed{}.Description() +} + +// Inst returns the underlying metric.Int64ObservableCounter, or nil for the +// zero TaskFailedObservable. +func (m TaskFailedObservable) Inst() metric.Int64ObservableCounter { + return m.inst } diff --git a/templates/code/go/tests/imported_typed/expected/myappspan/spans.go b/templates/code/go/tests/imported_typed/expected/myappspan/spans.go index e0281d1..cd29188 100644 --- a/templates/code/go/tests/imported_typed/expected/myappspan/spans.go +++ b/templates/code/go/tests/imported_typed/expected/myappspan/spans.go @@ -21,7 +21,7 @@ type TaskDispatchStartAttr interface { taskDispatchStartAttr() attribute.KeyValue } -// TaskDispatchAttr is an attribute a TaskDispatchSpan also accepts after it +// TaskDispatchAttr is an attribute a TaskDispatch also accepts after it // started, through SetAttributes. type TaskDispatchAttr interface { TaskDispatchStartAttr @@ -36,19 +36,19 @@ func (o taskDispatchSpanServerPort) taskDispatchStartAttr() attribute.KeyValue { func (taskDispatchSpanServerPort) taskDispatchAttr() {} -// WithTaskDispatchServerPort sets `server.port` on a TaskDispatchSpan, when +// WithTaskDispatchServerPort sets `server.port` on a TaskDispatch, when // StartTaskDispatch starts it or later through SetAttributes. func WithTaskDispatchServerPort(v int) TaskDispatchAttr { return taskDispatchSpanServerPort{v: v} } -// TaskDispatchSpan is a started span of `myapp.task.dispatch`. The zero -// TaskDispatchSpan records nothing. -type TaskDispatchSpan struct{ span trace.Span } +// TaskDispatch is a started span of `myapp.task.dispatch`. The zero +// TaskDispatch records nothing. +type TaskDispatch struct{ span trace.Span } // Span returns the underlying trace.Span, or a no-op one for the zero -// TaskDispatchSpan. -func (s TaskDispatchSpan) Span() trace.Span { +// TaskDispatch. +func (s TaskDispatch) Span() trace.Span { if s.span == nil { return noop.Span{} } @@ -56,12 +56,12 @@ func (s TaskDispatchSpan) Span() trace.Span { } // End ends the span. -func (s TaskDispatchSpan) End(opts ...trace.SpanEndOption) { +func (s TaskDispatch) End(opts ...trace.SpanEndOption) { s.Span().End(opts...) } // SetAttributes sets attributes on the span after it started. -func (s TaskDispatchSpan) SetAttributes(attrs ...TaskDispatchAttr) { +func (s TaskDispatch) SetAttributes(attrs ...TaskDispatchAttr) { kvs := make([]attribute.KeyValue, 0, len(attrs)) for _, attr := range attrs { kvs = append(kvs, attr.taskDispatchStartAttr()) @@ -70,12 +70,12 @@ func (s TaskDispatchSpan) SetAttributes(attrs ...TaskDispatchAttr) { } // RecordError records err as an exception event on the span. -func (s TaskDispatchSpan) RecordError(err error, opts ...trace.EventOption) { +func (s TaskDispatch) RecordError(err error, opts ...trace.EventOption) { s.Span().RecordError(err, opts...) } // SetStatus sets the status of the span. -func (s TaskDispatchSpan) SetStatus(code codes.Code, description string) { +func (s TaskDispatch) SetStatus(code codes.Code, description string) { s.Span().SetStatus(code, description) } @@ -86,7 +86,7 @@ func (s TaskDispatchSpan) SetStatus(code codes.Code, description string) { // // The span is named `task {myapp.task.id} failed with {error.type}`, with // each placeholder replaced by the value of the attribute it names. -func StartTaskDispatch(ctx context.Context, tracer myapptracer.Tracer, errorType errorattr.TypeAttr, myappTaskID myappattr.TaskIDAttr, opts ...TaskDispatchStartAttr) (context.Context, TaskDispatchSpan) { +func StartTaskDispatch(ctx context.Context, tracer myapptracer.Tracer, errorType errorattr.Type, myappTaskID myappattr.TaskID, opts ...TaskDispatchStartAttr) (context.Context, TaskDispatch) { kvs := make([]attribute.KeyValue, 0, 2+len(opts)) kvs = append(kvs, errorType.KeyValue()) kvs = append(kvs, myappTaskID.KeyValue()) @@ -100,5 +100,5 @@ func StartTaskDispatch(ctx context.Context, tracer myapptracer.Tracer, errorType trace.WithSpanKind(trace.SpanKindInternal), trace.WithAttributes(kvs...), ) - return ctx, TaskDispatchSpan{span: span} + return ctx, TaskDispatch{span: span} } diff --git a/templates/code/go/tests/metrics/expected/authattr/attributes.go b/templates/code/go/tests/metrics/expected/authattr/attributes.go index 26d1793..75e9ae0 100644 --- a/templates/code/go/tests/metrics/expected/authattr/attributes.go +++ b/templates/code/go/tests/metrics/expected/authattr/attributes.go @@ -7,18 +7,18 @@ import "go.opentelemetry.io/otel/attribute" // methodKey is the attribute key of `auth.method`. const methodKey = attribute.Key("auth.method") -// MethodAttr is a value of `auth.method`. +// Method is a value of `auth.method`. // // How the user was authenticated. -type MethodAttr struct{ value string } +type Method struct{ value string } // Key is the attribute key, for filters and views that need it. -func (MethodAttr) Key() attribute.Key { +func (Method) Key() attribute.Key { return methodKey } // KeyValue is the `auth.method` attribute set to this value. -func (v MethodAttr) KeyValue() attribute.KeyValue { +func (v Method) KeyValue() attribute.KeyValue { return methodKey.String(v.value) } @@ -26,33 +26,33 @@ var ( // MethodPassword is the "password" member of `auth.method`. // // A password was checked. - MethodPassword = MethodAttr{value: "password"} + MethodPassword = Method{value: "password"} // MethodToken is the "token" member of `auth.method`. // // A bearer token was checked. - MethodToken = MethodAttr{value: "token"} + MethodToken = Method{value: "token"} ) // successKey is the attribute key of `auth.success`. const successKey = attribute.Key("auth.success") -// SuccessAttr is a value of `auth.success`. +// Success is a value of `auth.success`. // // Whether the attempt succeeded. -type SuccessAttr struct{ value bool } +type Success struct{ value bool } -// NewSuccessAttr returns a value of `auth.success`. -func NewSuccessAttr(value bool) SuccessAttr { - return SuccessAttr{value: value} +// NewSuccess returns a value of `auth.success`. +func NewSuccess(value bool) Success { + return Success{value: value} } // Key is the attribute key, for filters and views that need it. -func (SuccessAttr) Key() attribute.Key { +func (Success) Key() attribute.Key { return successKey } // KeyValue is the `auth.success` attribute set to this value. -func (v SuccessAttr) KeyValue() attribute.KeyValue { +func (v Success) KeyValue() attribute.KeyValue { return successKey.Bool(v.value) } diff --git a/templates/code/go/tests/metrics/expected/authmetric/metrics.go b/templates/code/go/tests/metrics/expected/authmetric/metrics.go index e64356c..faec58d 100644 --- a/templates/code/go/tests/metrics/expected/authmetric/metrics.go +++ b/templates/code/go/tests/metrics/expected/authmetric/metrics.go @@ -13,27 +13,49 @@ import ( "example.com/semconv/semconvmeter" ) -// AttemptsCounter is `auth.attempts`. +// Attempts is `auth.attempts`. // // Number of authentication attempts. -type AttemptsCounter struct{ inst metric.Int64Counter } +type Attempts struct{ inst metric.Int64Counter } -// NewAttemptsCounter creates the `auth.attempts` instrument from meter. -func NewAttemptsCounter(meter semconvmeter.Meter) (AttemptsCounter, error) { +// NewAttempts creates the `auth.attempts` instrument from meter. +func NewAttempts(meter semconvmeter.Meter) (Attempts, error) { + var m Attempts inst, err := meter.MetricMeter().Int64Counter( - "auth.attempts", - metric.WithDescription("Number of authentication attempts."), - metric.WithUnit("{attempt}"), + m.Name(), + metric.WithDescription(m.Description()), + metric.WithUnit(m.Unit()), ) if err != nil { - return AttemptsCounter{}, fmt.Errorf("create the %s instrument: %w", "auth.attempts", err) + return Attempts{}, fmt.Errorf("create the %s instrument: %w", m.Name(), err) } - return AttemptsCounter{inst: inst}, nil + return Attempts{inst: inst}, nil } -// Add records one `auth.attempts` measurement. The zero AttemptsCounter -// records nothing. -func (m AttemptsCounter) Add(ctx context.Context, incr int64, authMethod authattr.MethodAttr, authSuccess authattr.SuccessAttr) { +// Name returns the name `auth.attempts` records under. +func (Attempts) Name() string { + return "auth.attempts" +} + +// Unit returns the unit of `auth.attempts`. +func (Attempts) Unit() string { + return "{attempt}" +} + +// Description returns the description of `auth.attempts`. +func (Attempts) Description() string { + return "Number of authentication attempts." +} + +// Inst returns the underlying metric.Int64Counter, or nil for the zero +// Attempts. +func (m Attempts) Inst() metric.Int64Counter { + return m.inst +} + +// Add records one `auth.attempts` measurement. The zero Attempts records +// nothing. +func (m Attempts) Add(ctx context.Context, incr int64, authMethod authattr.Method, authSuccess authattr.Success) { if m.inst == nil { return } @@ -43,15 +65,14 @@ func (m AttemptsCounter) Add(ctx context.Context, incr int64, authMethod authatt m.inst.Add(ctx, incr, metric.WithAttributes(kvs...)) } -// AttemptsCounterObserver records `auth.attempts` observations from the -// callback of a AttemptsObservableCounter. The zero AttemptsCounterObserver -// records nothing. -type AttemptsCounterObserver struct { +// AttemptsObserver records `auth.attempts` observations from the callback of +// a AttemptsObservable. The zero AttemptsObserver records nothing. +type AttemptsObserver struct { o metric.Int64Observer } // Observe records one `auth.attempts` observation. -func (o AttemptsCounterObserver) Observe(value int64, authMethod authattr.MethodAttr, authSuccess authattr.SuccessAttr) { +func (o AttemptsObserver) Observe(value int64, authMethod authattr.Method, authSuccess authattr.Success) { if o.o == nil { return } @@ -61,35 +82,57 @@ func (o AttemptsCounterObserver) Observe(value int64, authMethod authattr.Method o.o.Observe(value, metric.WithAttributes(kvs...)) } -// AttemptsCounterCallback observes `auth.attempts` through o on every -// collection of a AttemptsObservableCounter. +// AttemptsCallback observes `auth.attempts` through o on every collection of +// a AttemptsObservable. // // An error it returns is returned by the collection that ran it, and the // observations made before it returned are still recorded. -type AttemptsCounterCallback func(ctx context.Context, o AttemptsCounterObserver) error +type AttemptsCallback func(ctx context.Context, o AttemptsObserver) error -// AttemptsObservableCounter is the asynchronous form of AttemptsCounter, -// observed through the callback it was created with. -type AttemptsObservableCounter struct { +// AttemptsObservable is the asynchronous form of Attempts, observed through +// the callback it was created with. +type AttemptsObservable struct { inst metric.Int64ObservableCounter } -// NewAttemptsObservableCounter creates the `auth.attempts` instrument from -// meter and registers callback to observe it on every collection. -func NewAttemptsObservableCounter(meter semconvmeter.Meter, callback AttemptsCounterCallback) (AttemptsObservableCounter, error) { +// NewAttemptsObservable creates the `auth.attempts` instrument from meter +// and registers callback to observe it on every collection. +func NewAttemptsObservable(meter semconvmeter.Meter, callback AttemptsCallback) (AttemptsObservable, error) { + var m AttemptsObservable if callback == nil { - return AttemptsObservableCounter{}, fmt.Errorf("create the %s instrument: the callback is nil", "auth.attempts") + return AttemptsObservable{}, fmt.Errorf("create the %s instrument: the callback is nil", m.Name()) } inst, err := meter.MetricMeter().Int64ObservableCounter( - "auth.attempts", - metric.WithDescription("Number of authentication attempts."), - metric.WithUnit("{attempt}"), + m.Name(), + metric.WithDescription(m.Description()), + metric.WithUnit(m.Unit()), metric.WithInt64Callback(func(ctx context.Context, o metric.Int64Observer) error { - return callback(ctx, AttemptsCounterObserver{o: o}) + return callback(ctx, AttemptsObserver{o: o}) }), ) if err != nil { - return AttemptsObservableCounter{}, fmt.Errorf("create the %s instrument: %w", "auth.attempts", err) + return AttemptsObservable{}, fmt.Errorf("create the %s instrument: %w", m.Name(), err) } - return AttemptsObservableCounter{inst: inst}, nil + return AttemptsObservable{inst: inst}, nil +} + +// Name returns the name `auth.attempts` records under. +func (AttemptsObservable) Name() string { + return Attempts{}.Name() +} + +// Unit returns the unit of `auth.attempts`. +func (AttemptsObservable) Unit() string { + return Attempts{}.Unit() +} + +// Description returns the description of `auth.attempts`. +func (AttemptsObservable) Description() string { + return Attempts{}.Description() +} + +// Inst returns the underlying metric.Int64ObservableCounter, or nil for the +// zero AttemptsObservable. +func (m AttemptsObservable) Inst() metric.Int64ObservableCounter { + return m.inst } diff --git a/templates/code/go/tests/metrics/expected/myappattr/attributes.go b/templates/code/go/tests/metrics/expected/myappattr/attributes.go index c684e9e..85499e4 100644 --- a/templates/code/go/tests/metrics/expected/myappattr/attributes.go +++ b/templates/code/go/tests/metrics/expected/myappattr/attributes.go @@ -7,41 +7,41 @@ import "go.opentelemetry.io/otel/attribute" // taskIDKey is the attribute key of `myapp.task.id`. const taskIDKey = attribute.Key("myapp.task.id") -// TaskIDAttr is a value of `myapp.task.id`. +// TaskID is a value of `myapp.task.id`. // // Unique identifier of the task. -type TaskIDAttr struct{ value string } +type TaskID struct{ value string } -// NewTaskIDAttr returns a value of `myapp.task.id`. -func NewTaskIDAttr(value string) TaskIDAttr { - return TaskIDAttr{value: value} +// NewTaskID returns a value of `myapp.task.id`. +func NewTaskID(value string) TaskID { + return TaskID{value: value} } // Key is the attribute key, for filters and views that need it. -func (TaskIDAttr) Key() attribute.Key { +func (TaskID) Key() attribute.Key { return taskIDKey } // KeyValue is the `myapp.task.id` attribute set to this value. -func (v TaskIDAttr) KeyValue() attribute.KeyValue { +func (v TaskID) KeyValue() attribute.KeyValue { return taskIDKey.String(v.value) } // taskStateKey is the attribute key of `myapp.task.state`. const taskStateKey = attribute.Key("myapp.task.state") -// TaskStateAttr is a value of `myapp.task.state`. +// TaskState is a value of `myapp.task.state`. // // Current state of the task. -type TaskStateAttr struct{ value string } +type TaskState struct{ value string } // Key is the attribute key, for filters and views that need it. -func (TaskStateAttr) Key() attribute.Key { +func (TaskState) Key() attribute.Key { return taskStateKey } // KeyValue is the `myapp.task.state` attribute set to this value. -func (v TaskStateAttr) KeyValue() attribute.KeyValue { +func (v TaskState) KeyValue() attribute.KeyValue { return taskStateKey.String(v.value) } @@ -49,10 +49,10 @@ var ( // TaskStateQueued is the "queued" member of `myapp.task.state`. // // The task is waiting to run. - TaskStateQueued = TaskStateAttr{value: "queued"} + TaskStateQueued = TaskState{value: "queued"} // TaskStateDone is the "done" member of `myapp.task.state`. // // The task finished. - TaskStateDone = TaskStateAttr{value: "done"} + TaskStateDone = TaskState{value: "done"} ) diff --git a/templates/code/go/tests/metrics/expected/myappmetric/metrics.go b/templates/code/go/tests/metrics/expected/myappmetric/metrics.go index c0b918a..8bcc6a3 100644 --- a/templates/code/go/tests/metrics/expected/myappmetric/metrics.go +++ b/templates/code/go/tests/metrics/expected/myappmetric/metrics.go @@ -14,113 +14,178 @@ import ( "example.com/semconv/semconvmeter" ) -// QueueDepthGauge is `myapp.queue.depth`. +// QueueDepth is `myapp.queue.depth`. // // Number of tasks waiting in the queue. // // Deprecated: Replaced by `myapp.task.active`. -type QueueDepthGauge struct{ inst metric.Int64Gauge } +type QueueDepth struct{ inst metric.Int64Gauge } -// NewQueueDepthGauge creates the `myapp.queue.depth` instrument from meter. +// NewQueueDepth creates the `myapp.queue.depth` instrument from meter. // // Deprecated: Replaced by `myapp.task.active`. -func NewQueueDepthGauge(meter semconvmeter.Meter) (QueueDepthGauge, error) { +func NewQueueDepth(meter semconvmeter.Meter) (QueueDepth, error) { + var m QueueDepth inst, err := meter.MetricMeter().Int64Gauge( - "myapp.queue.depth", - metric.WithDescription("Number of tasks waiting in the queue."), - metric.WithUnit("{task}"), + m.Name(), + metric.WithDescription(m.Description()), + metric.WithUnit(m.Unit()), ) if err != nil { - return QueueDepthGauge{}, fmt.Errorf("create the %s instrument: %w", "myapp.queue.depth", err) + return QueueDepth{}, fmt.Errorf("create the %s instrument: %w", m.Name(), err) } - return QueueDepthGauge{inst: inst}, nil + return QueueDepth{inst: inst}, nil } -// Record records one `myapp.queue.depth` measurement. The zero -// QueueDepthGauge records nothing. -func (m QueueDepthGauge) Record(ctx context.Context, value int64) { +// Name returns the name `myapp.queue.depth` records under. +func (QueueDepth) Name() string { + return "myapp.queue.depth" +} + +// Unit returns the unit of `myapp.queue.depth`. +func (QueueDepth) Unit() string { + return "{task}" +} + +// Description returns the description of `myapp.queue.depth`. +func (QueueDepth) Description() string { + return "Number of tasks waiting in the queue." +} + +// Inst returns the underlying metric.Int64Gauge, or nil for the zero +// QueueDepth. +func (m QueueDepth) Inst() metric.Int64Gauge { + return m.inst +} + +// Record records one `myapp.queue.depth` measurement. The zero QueueDepth +// records nothing. +func (m QueueDepth) Record(ctx context.Context, value int64) { if m.inst == nil { return } m.inst.Record(ctx, value) } -// QueueDepthGaugeObserver records `myapp.queue.depth` observations from the -// callback of a QueueDepthObservableGauge. The zero QueueDepthGaugeObserver -// records nothing. -type QueueDepthGaugeObserver struct { +// QueueDepthObserver records `myapp.queue.depth` observations from the +// callback of a QueueDepthObservable. The zero QueueDepthObserver records +// nothing. +type QueueDepthObserver struct { o metric.Int64Observer } // Observe records one `myapp.queue.depth` observation. -func (o QueueDepthGaugeObserver) Observe(value int64) { +func (o QueueDepthObserver) Observe(value int64) { if o.o == nil { return } o.o.Observe(value) } -// QueueDepthGaugeCallback observes `myapp.queue.depth` through o on every -// collection of a QueueDepthObservableGauge. +// QueueDepthCallback observes `myapp.queue.depth` through o on every +// collection of a QueueDepthObservable. // // An error it returns is returned by the collection that ran it, and the // observations made before it returned are still recorded. // // Deprecated: Replaced by `myapp.task.active`. -type QueueDepthGaugeCallback func(ctx context.Context, o QueueDepthGaugeObserver) error +type QueueDepthCallback func(ctx context.Context, o QueueDepthObserver) error -// QueueDepthObservableGauge is the asynchronous form of QueueDepthGauge, -// observed through the callback it was created with. +// QueueDepthObservable is the asynchronous form of QueueDepth, observed +// through the callback it was created with. // // Deprecated: Replaced by `myapp.task.active`. -type QueueDepthObservableGauge struct { +type QueueDepthObservable struct { inst metric.Int64ObservableGauge } -// NewQueueDepthObservableGauge creates the `myapp.queue.depth` instrument -// from meter and registers callback to observe it on every collection. +// NewQueueDepthObservable creates the `myapp.queue.depth` instrument from +// meter and registers callback to observe it on every collection. // // Deprecated: Replaced by `myapp.task.active`. -func NewQueueDepthObservableGauge(meter semconvmeter.Meter, callback QueueDepthGaugeCallback) (QueueDepthObservableGauge, error) { +func NewQueueDepthObservable(meter semconvmeter.Meter, callback QueueDepthCallback) (QueueDepthObservable, error) { + var m QueueDepthObservable if callback == nil { - return QueueDepthObservableGauge{}, fmt.Errorf("create the %s instrument: the callback is nil", "myapp.queue.depth") + return QueueDepthObservable{}, fmt.Errorf("create the %s instrument: the callback is nil", m.Name()) } inst, err := meter.MetricMeter().Int64ObservableGauge( - "myapp.queue.depth", - metric.WithDescription("Number of tasks waiting in the queue."), - metric.WithUnit("{task}"), + m.Name(), + metric.WithDescription(m.Description()), + metric.WithUnit(m.Unit()), metric.WithInt64Callback(func(ctx context.Context, o metric.Int64Observer) error { - return callback(ctx, QueueDepthGaugeObserver{o: o}) + return callback(ctx, QueueDepthObserver{o: o}) }), ) if err != nil { - return QueueDepthObservableGauge{}, fmt.Errorf("create the %s instrument: %w", "myapp.queue.depth", err) + return QueueDepthObservable{}, fmt.Errorf("create the %s instrument: %w", m.Name(), err) } - return QueueDepthObservableGauge{inst: inst}, nil + return QueueDepthObservable{inst: inst}, nil +} + +// Name returns the name `myapp.queue.depth` records under. +func (QueueDepthObservable) Name() string { + return QueueDepth{}.Name() +} + +// Unit returns the unit of `myapp.queue.depth`. +func (QueueDepthObservable) Unit() string { + return QueueDepth{}.Unit() +} + +// Description returns the description of `myapp.queue.depth`. +func (QueueDepthObservable) Description() string { + return QueueDepth{}.Description() +} + +// Inst returns the underlying metric.Int64ObservableGauge, or nil for the +// zero QueueDepthObservable. +func (m QueueDepthObservable) Inst() metric.Int64ObservableGauge { + return m.inst } -// TaskActiveUpDownCounter is `myapp.task.active`. +// TaskActive is `myapp.task.active`. // // Number of tasks currently running. -type TaskActiveUpDownCounter struct{ inst metric.Int64UpDownCounter } +type TaskActive struct{ inst metric.Int64UpDownCounter } -// NewTaskActiveUpDownCounter creates the `myapp.task.active` instrument from -// meter. -func NewTaskActiveUpDownCounter(meter semconvmeter.Meter) (TaskActiveUpDownCounter, error) { +// NewTaskActive creates the `myapp.task.active` instrument from meter. +func NewTaskActive(meter semconvmeter.Meter) (TaskActive, error) { + var m TaskActive inst, err := meter.MetricMeter().Int64UpDownCounter( - "myapp.task.active", - metric.WithDescription("Number of tasks currently running."), - metric.WithUnit("{task}"), + m.Name(), + metric.WithDescription(m.Description()), + metric.WithUnit(m.Unit()), ) if err != nil { - return TaskActiveUpDownCounter{}, fmt.Errorf("create the %s instrument: %w", "myapp.task.active", err) + return TaskActive{}, fmt.Errorf("create the %s instrument: %w", m.Name(), err) } - return TaskActiveUpDownCounter{inst: inst}, nil + return TaskActive{inst: inst}, nil +} + +// Name returns the name `myapp.task.active` records under. +func (TaskActive) Name() string { + return "myapp.task.active" +} + +// Unit returns the unit of `myapp.task.active`. +func (TaskActive) Unit() string { + return "{task}" +} + +// Description returns the description of `myapp.task.active`. +func (TaskActive) Description() string { + return "Number of tasks currently running." +} + +// Inst returns the underlying metric.Int64UpDownCounter, or nil for the zero +// TaskActive. +func (m TaskActive) Inst() metric.Int64UpDownCounter { + return m.inst } -// Add records one `myapp.task.active` measurement. The zero -// TaskActiveUpDownCounter records nothing. -func (m TaskActiveUpDownCounter) Add(ctx context.Context, incr int64, myappTaskState myappattr.TaskStateAttr) { +// Add records one `myapp.task.active` measurement. The zero TaskActive +// records nothing. +func (m TaskActive) Add(ctx context.Context, incr int64, myappTaskState myappattr.TaskState) { if m.inst == nil { return } @@ -129,15 +194,15 @@ func (m TaskActiveUpDownCounter) Add(ctx context.Context, incr int64, myappTaskS m.inst.Add(ctx, incr, metric.WithAttributes(kvs...)) } -// TaskActiveUpDownCounterObserver records `myapp.task.active` observations -// from the callback of a TaskActiveObservableUpDownCounter. The zero -// TaskActiveUpDownCounterObserver records nothing. -type TaskActiveUpDownCounterObserver struct { +// TaskActiveObserver records `myapp.task.active` observations from the +// callback of a TaskActiveObservable. The zero TaskActiveObserver records +// nothing. +type TaskActiveObserver struct { o metric.Int64Observer } // Observe records one `myapp.task.active` observation. -func (o TaskActiveUpDownCounterObserver) Observe(value int64, myappTaskState myappattr.TaskStateAttr) { +func (o TaskActiveObserver) Observe(value int64, myappTaskState myappattr.TaskState) { if o.o == nil { return } @@ -146,158 +211,217 @@ func (o TaskActiveUpDownCounterObserver) Observe(value int64, myappTaskState mya o.o.Observe(value, metric.WithAttributes(kvs...)) } -// TaskActiveUpDownCounterCallback observes `myapp.task.active` through o on -// every collection of a TaskActiveObservableUpDownCounter. +// TaskActiveCallback observes `myapp.task.active` through o on every +// collection of a TaskActiveObservable. // // An error it returns is returned by the collection that ran it, and the // observations made before it returned are still recorded. -type TaskActiveUpDownCounterCallback func(ctx context.Context, o TaskActiveUpDownCounterObserver) error +type TaskActiveCallback func(ctx context.Context, o TaskActiveObserver) error -// TaskActiveObservableUpDownCounter is the asynchronous form of -// TaskActiveUpDownCounter, observed through the callback it was created -// with. -type TaskActiveObservableUpDownCounter struct { +// TaskActiveObservable is the asynchronous form of TaskActive, observed +// through the callback it was created with. +type TaskActiveObservable struct { inst metric.Int64ObservableUpDownCounter } -// NewTaskActiveObservableUpDownCounter creates the `myapp.task.active` -// instrument from meter and registers callback to observe it on every -// collection. -func NewTaskActiveObservableUpDownCounter(meter semconvmeter.Meter, callback TaskActiveUpDownCounterCallback) (TaskActiveObservableUpDownCounter, error) { +// NewTaskActiveObservable creates the `myapp.task.active` instrument from +// meter and registers callback to observe it on every collection. +func NewTaskActiveObservable(meter semconvmeter.Meter, callback TaskActiveCallback) (TaskActiveObservable, error) { + var m TaskActiveObservable if callback == nil { - return TaskActiveObservableUpDownCounter{}, fmt.Errorf("create the %s instrument: the callback is nil", "myapp.task.active") + return TaskActiveObservable{}, fmt.Errorf("create the %s instrument: the callback is nil", m.Name()) } inst, err := meter.MetricMeter().Int64ObservableUpDownCounter( - "myapp.task.active", - metric.WithDescription("Number of tasks currently running."), - metric.WithUnit("{task}"), + m.Name(), + metric.WithDescription(m.Description()), + metric.WithUnit(m.Unit()), metric.WithInt64Callback(func(ctx context.Context, o metric.Int64Observer) error { - return callback(ctx, TaskActiveUpDownCounterObserver{o: o}) + return callback(ctx, TaskActiveObserver{o: o}) }), ) if err != nil { - return TaskActiveObservableUpDownCounter{}, fmt.Errorf("create the %s instrument: %w", "myapp.task.active", err) + return TaskActiveObservable{}, fmt.Errorf("create the %s instrument: %w", m.Name(), err) } - return TaskActiveObservableUpDownCounter{inst: inst}, nil + return TaskActiveObservable{inst: inst}, nil +} + +// Name returns the name `myapp.task.active` records under. +func (TaskActiveObservable) Name() string { + return TaskActive{}.Name() +} + +// Unit returns the unit of `myapp.task.active`. +func (TaskActiveObservable) Unit() string { + return TaskActive{}.Unit() +} + +// Description returns the description of `myapp.task.active`. +func (TaskActiveObservable) Description() string { + return TaskActive{}.Description() +} + +// Inst returns the underlying metric.Int64ObservableUpDownCounter, or nil +// for the zero TaskActiveObservable. +func (m TaskActiveObservable) Inst() metric.Int64ObservableUpDownCounter { + return m.inst } -// TaskDurationHistogramAttr is an attribute `myapp.task.duration` accepts in -// addition to the ones TaskDurationHistogram.Record requires. -type TaskDurationHistogramAttr interface { - taskDurationHistogramAttr() attribute.KeyValue +// TaskDurationAttr is an attribute `myapp.task.duration` accepts in addition +// to the ones TaskDuration.Record requires. +type TaskDurationAttr interface { + taskDurationAttr() attribute.KeyValue } -type taskDurationHistogramMethod struct{ v authattr.MethodAttr } +type taskDurationMethod struct{ v authattr.Method } -func (o taskDurationHistogramMethod) taskDurationHistogramAttr() attribute.KeyValue { +func (o taskDurationMethod) taskDurationAttr() attribute.KeyValue { return o.v.KeyValue() } -// WithTaskDurationHistogramMethod attaches `auth.method` to -// TaskDurationHistogram. +// WithTaskDurationMethod attaches `auth.method` to TaskDuration. // // Opt-in: the convention records it only when a user asks for it. -func WithTaskDurationHistogramMethod(v authattr.MethodAttr) TaskDurationHistogramAttr { - return taskDurationHistogramMethod{v: v} +func WithTaskDurationMethod(v authattr.Method) TaskDurationAttr { + return taskDurationMethod{v: v} } -type taskDurationHistogramTaskState struct{ v myappattr.TaskStateAttr } +type taskDurationTaskState struct{ v myappattr.TaskState } -func (o taskDurationHistogramTaskState) taskDurationHistogramAttr() attribute.KeyValue { +func (o taskDurationTaskState) taskDurationAttr() attribute.KeyValue { return o.v.KeyValue() } -// WithTaskDurationHistogramTaskState attaches `myapp.task.state` to -// TaskDurationHistogram. +// WithTaskDurationTaskState attaches `myapp.task.state` to TaskDuration. // // Conditionally required: If the task reached a final state. -func WithTaskDurationHistogramTaskState(v myappattr.TaskStateAttr) TaskDurationHistogramAttr { - return taskDurationHistogramTaskState{v: v} +func WithTaskDurationTaskState(v myappattr.TaskState) TaskDurationAttr { + return taskDurationTaskState{v: v} } -// TaskDurationHistogram is `myapp.task.duration`. +// TaskDuration is `myapp.task.duration`. // // Time a task took from start to finish. // // Measured by the worker that ran the task. -type TaskDurationHistogram struct{ inst metric.Float64Histogram } +type TaskDuration struct{ inst metric.Float64Histogram } -// NewTaskDurationHistogram creates the `myapp.task.duration` instrument from -// meter. -func NewTaskDurationHistogram(meter semconvmeter.Meter) (TaskDurationHistogram, error) { +// NewTaskDuration creates the `myapp.task.duration` instrument from meter. +func NewTaskDuration(meter semconvmeter.Meter) (TaskDuration, error) { + var m TaskDuration inst, err := meter.MetricMeter().Float64Histogram( - "myapp.task.duration", - metric.WithDescription("Time a task took from start to finish."), - metric.WithUnit("s"), + m.Name(), + metric.WithDescription(m.Description()), + metric.WithUnit(m.Unit()), metric.WithExplicitBucketBoundaries(0, 0.005, 0.01, 0.1, 1, 10), ) if err != nil { - return TaskDurationHistogram{}, fmt.Errorf("create the %s instrument: %w", "myapp.task.duration", err) + return TaskDuration{}, fmt.Errorf("create the %s instrument: %w", m.Name(), err) } - return TaskDurationHistogram{inst: inst}, nil + return TaskDuration{inst: inst}, nil +} + +// Name returns the name `myapp.task.duration` records under. +func (TaskDuration) Name() string { + return "myapp.task.duration" +} + +// Unit returns the unit of `myapp.task.duration`. +func (TaskDuration) Unit() string { + return "s" +} + +// Description returns the description of `myapp.task.duration`. +func (TaskDuration) Description() string { + return "Time a task took from start to finish." +} + +// Inst returns the underlying metric.Float64Histogram, or nil for the zero +// TaskDuration. +func (m TaskDuration) Inst() metric.Float64Histogram { + return m.inst } // Record records one `myapp.task.duration` measurement. The zero -// TaskDurationHistogram records nothing. -func (m TaskDurationHistogram) Record(ctx context.Context, value float64, myappTaskID myappattr.TaskIDAttr, opts ...TaskDurationHistogramAttr) { +// TaskDuration records nothing. +func (m TaskDuration) Record(ctx context.Context, value float64, myappTaskID myappattr.TaskID, opts ...TaskDurationAttr) { if m.inst == nil { return } kvs := make([]attribute.KeyValue, 0, 1+len(opts)) kvs = append(kvs, myappTaskID.KeyValue()) for _, opt := range opts { - kvs = append(kvs, opt.taskDurationHistogramAttr()) + kvs = append(kvs, opt.taskDurationAttr()) } m.inst.Record(ctx, value, metric.WithAttributes(kvs...)) } -// TaskRetryDurationHistogramAttr is an attribute `myapp.task.retry.duration` -// accepts in addition to the ones TaskRetryDurationHistogram.Record -// requires. -type TaskRetryDurationHistogramAttr interface { - taskRetryDurationHistogramAttr() attribute.KeyValue +// TaskRetryDurationAttr is an attribute `myapp.task.retry.duration` accepts +// in addition to the ones TaskRetryDuration.Record requires. +type TaskRetryDurationAttr interface { + taskRetryDurationAttr() attribute.KeyValue } -type taskRetryDurationHistogramMethod struct{ v authattr.MethodAttr } +type taskRetryDurationMethod struct{ v authattr.Method } -func (o taskRetryDurationHistogramMethod) taskRetryDurationHistogramAttr() attribute.KeyValue { +func (o taskRetryDurationMethod) taskRetryDurationAttr() attribute.KeyValue { return o.v.KeyValue() } -// WithTaskRetryDurationHistogramMethod attaches `auth.method` to -// TaskRetryDurationHistogram. +// WithTaskRetryDurationMethod attaches `auth.method` to TaskRetryDuration. // // Opt-in: the convention records it only when a user asks for it. -func WithTaskRetryDurationHistogramMethod(v authattr.MethodAttr) TaskRetryDurationHistogramAttr { - return taskRetryDurationHistogramMethod{v: v} +func WithTaskRetryDurationMethod(v authattr.Method) TaskRetryDurationAttr { + return taskRetryDurationMethod{v: v} } -// TaskRetryDurationHistogram is `myapp.task.retry.duration`, a refinement of +// TaskRetryDuration is `myapp.task.retry.duration`, a refinement of // `myapp.task.duration` that records under that metric's name. // // Time a retried task took from start to finish. // // Recorded only for tasks that ran more than once. -type TaskRetryDurationHistogram struct{ inst metric.Float64Histogram } +type TaskRetryDuration struct{ inst metric.Float64Histogram } -// NewTaskRetryDurationHistogram creates the `myapp.task.duration` instrument -// from meter. -func NewTaskRetryDurationHistogram(meter semconvmeter.Meter) (TaskRetryDurationHistogram, error) { +// NewTaskRetryDuration creates the `myapp.task.duration` instrument from +// meter. +func NewTaskRetryDuration(meter semconvmeter.Meter) (TaskRetryDuration, error) { + var m TaskRetryDuration inst, err := meter.MetricMeter().Float64Histogram( - "myapp.task.duration", - metric.WithDescription("Time a task took from start to finish."), - metric.WithUnit("s"), + m.Name(), + metric.WithDescription(m.Description()), + metric.WithUnit(m.Unit()), metric.WithExplicitBucketBoundaries(0, 0.005, 0.01, 0.1, 1, 10), ) if err != nil { - return TaskRetryDurationHistogram{}, fmt.Errorf("create the %s instrument: %w", "myapp.task.duration", err) + return TaskRetryDuration{}, fmt.Errorf("create the %s instrument: %w", m.Name(), err) } - return TaskRetryDurationHistogram{inst: inst}, nil + return TaskRetryDuration{inst: inst}, nil +} + +// Name returns the name `myapp.task.retry.duration` records under. +func (TaskRetryDuration) Name() string { + return "myapp.task.duration" +} + +// Unit returns the unit of `myapp.task.retry.duration`. +func (TaskRetryDuration) Unit() string { + return "s" +} + +// Description returns the description of `myapp.task.retry.duration`. +func (TaskRetryDuration) Description() string { + return "Time a task took from start to finish." +} + +// Inst returns the underlying metric.Float64Histogram, or nil for the zero +// TaskRetryDuration. +func (m TaskRetryDuration) Inst() metric.Float64Histogram { + return m.inst } // Record records one `myapp.task.retry.duration` measurement. The zero -// TaskRetryDurationHistogram records nothing. -func (m TaskRetryDurationHistogram) Record(ctx context.Context, value float64, myappTaskID myappattr.TaskIDAttr, myappTaskState myappattr.TaskStateAttr, opts ...TaskRetryDurationHistogramAttr) { +// TaskRetryDuration records nothing. +func (m TaskRetryDuration) Record(ctx context.Context, value float64, myappTaskID myappattr.TaskID, myappTaskState myappattr.TaskState, opts ...TaskRetryDurationAttr) { if m.inst == nil { return } @@ -305,124 +429,165 @@ func (m TaskRetryDurationHistogram) Record(ctx context.Context, value float64, m kvs = append(kvs, myappTaskID.KeyValue()) kvs = append(kvs, myappTaskState.KeyValue()) for _, opt := range opts { - kvs = append(kvs, opt.taskRetryDurationHistogramAttr()) + kvs = append(kvs, opt.taskRetryDurationAttr()) } m.inst.Record(ctx, value, metric.WithAttributes(kvs...)) } -// TaskStartedCounterAttr is an attribute `myapp.task.started` accepts in -// addition to the ones TaskStartedCounter.Add requires. -type TaskStartedCounterAttr interface { - taskStartedCounterAttr() attribute.KeyValue +// TaskStartedAttr is an attribute `myapp.task.started` accepts in addition +// to the ones TaskStarted.Add requires. +type TaskStartedAttr interface { + taskStartedAttr() attribute.KeyValue } -type taskStartedCounterTaskID struct{ v myappattr.TaskIDAttr } +type taskStartedTaskID struct{ v myappattr.TaskID } -func (o taskStartedCounterTaskID) taskStartedCounterAttr() attribute.KeyValue { +func (o taskStartedTaskID) taskStartedAttr() attribute.KeyValue { return o.v.KeyValue() } -// WithTaskStartedCounterTaskID attaches `myapp.task.id` to -// TaskStartedCounter. +// WithTaskStartedTaskID attaches `myapp.task.id` to TaskStarted. // // Recommended: When the scheduler assigned an id before the task started. -func WithTaskStartedCounterTaskID(v myappattr.TaskIDAttr) TaskStartedCounterAttr { - return taskStartedCounterTaskID{v: v} +func WithTaskStartedTaskID(v myappattr.TaskID) TaskStartedAttr { + return taskStartedTaskID{v: v} } -// TaskStartedCounter is `myapp.task.started`. +// TaskStarted is `myapp.task.started`. // // Number of tasks started. // // Opt-in: the convention records `myapp.task.started` only when a user asks // for it. -type TaskStartedCounter struct{ inst metric.Int64Counter } +type TaskStarted struct{ inst metric.Int64Counter } -// NewTaskStartedCounter creates the `myapp.task.started` instrument from -// meter. +// NewTaskStarted creates the `myapp.task.started` instrument from meter. // // Opt-in: the convention records `myapp.task.started` only when a user asks // for it. -func NewTaskStartedCounter(meter semconvmeter.Meter) (TaskStartedCounter, error) { +func NewTaskStarted(meter semconvmeter.Meter) (TaskStarted, error) { + var m TaskStarted inst, err := meter.MetricMeter().Int64Counter( - "myapp.task.started", - metric.WithDescription("Number of tasks started."), - metric.WithUnit("{task}"), + m.Name(), + metric.WithDescription(m.Description()), + metric.WithUnit(m.Unit()), ) if err != nil { - return TaskStartedCounter{}, fmt.Errorf("create the %s instrument: %w", "myapp.task.started", err) + return TaskStarted{}, fmt.Errorf("create the %s instrument: %w", m.Name(), err) } - return TaskStartedCounter{inst: inst}, nil + return TaskStarted{inst: inst}, nil +} + +// Name returns the name `myapp.task.started` records under. +func (TaskStarted) Name() string { + return "myapp.task.started" +} + +// Unit returns the unit of `myapp.task.started`. +func (TaskStarted) Unit() string { + return "{task}" +} + +// Description returns the description of `myapp.task.started`. +func (TaskStarted) Description() string { + return "Number of tasks started." +} + +// Inst returns the underlying metric.Int64Counter, or nil for the zero +// TaskStarted. +func (m TaskStarted) Inst() metric.Int64Counter { + return m.inst } -// Add records one `myapp.task.started` measurement. The zero -// TaskStartedCounter records nothing. -func (m TaskStartedCounter) Add(ctx context.Context, incr int64, opts ...TaskStartedCounterAttr) { +// Add records one `myapp.task.started` measurement. The zero TaskStarted +// records nothing. +func (m TaskStarted) Add(ctx context.Context, incr int64, opts ...TaskStartedAttr) { if m.inst == nil { return } kvs := make([]attribute.KeyValue, 0, 0+len(opts)) for _, opt := range opts { - kvs = append(kvs, opt.taskStartedCounterAttr()) + kvs = append(kvs, opt.taskStartedAttr()) } m.inst.Add(ctx, incr, metric.WithAttributes(kvs...)) } -// TaskStartedCounterObserver records `myapp.task.started` observations from -// the callback of a TaskStartedObservableCounter. The zero -// TaskStartedCounterObserver records nothing. -type TaskStartedCounterObserver struct { +// TaskStartedObserver records `myapp.task.started` observations from the +// callback of a TaskStartedObservable. The zero TaskStartedObserver records +// nothing. +type TaskStartedObserver struct { o metric.Int64Observer } // Observe records one `myapp.task.started` observation. -func (o TaskStartedCounterObserver) Observe(value int64, opts ...TaskStartedCounterAttr) { +func (o TaskStartedObserver) Observe(value int64, opts ...TaskStartedAttr) { if o.o == nil { return } kvs := make([]attribute.KeyValue, 0, 0+len(opts)) for _, opt := range opts { - kvs = append(kvs, opt.taskStartedCounterAttr()) + kvs = append(kvs, opt.taskStartedAttr()) } o.o.Observe(value, metric.WithAttributes(kvs...)) } -// TaskStartedCounterCallback observes `myapp.task.started` through o on -// every collection of a TaskStartedObservableCounter. +// TaskStartedCallback observes `myapp.task.started` through o on every +// collection of a TaskStartedObservable. // // An error it returns is returned by the collection that ran it, and the // observations made before it returned are still recorded. -type TaskStartedCounterCallback func(ctx context.Context, o TaskStartedCounterObserver) error +type TaskStartedCallback func(ctx context.Context, o TaskStartedObserver) error -// TaskStartedObservableCounter is the asynchronous form of -// TaskStartedCounter, observed through the callback it was created with. +// TaskStartedObservable is the asynchronous form of TaskStarted, observed +// through the callback it was created with. // // Opt-in: the convention records `myapp.task.started` only when a user asks // for it. -type TaskStartedObservableCounter struct { +type TaskStartedObservable struct { inst metric.Int64ObservableCounter } -// NewTaskStartedObservableCounter creates the `myapp.task.started` -// instrument from meter and registers callback to observe it on every -// collection. +// NewTaskStartedObservable creates the `myapp.task.started` instrument from +// meter and registers callback to observe it on every collection. // // Opt-in: the convention records `myapp.task.started` only when a user asks // for it. -func NewTaskStartedObservableCounter(meter semconvmeter.Meter, callback TaskStartedCounterCallback) (TaskStartedObservableCounter, error) { +func NewTaskStartedObservable(meter semconvmeter.Meter, callback TaskStartedCallback) (TaskStartedObservable, error) { + var m TaskStartedObservable if callback == nil { - return TaskStartedObservableCounter{}, fmt.Errorf("create the %s instrument: the callback is nil", "myapp.task.started") + return TaskStartedObservable{}, fmt.Errorf("create the %s instrument: the callback is nil", m.Name()) } inst, err := meter.MetricMeter().Int64ObservableCounter( - "myapp.task.started", - metric.WithDescription("Number of tasks started."), - metric.WithUnit("{task}"), + m.Name(), + metric.WithDescription(m.Description()), + metric.WithUnit(m.Unit()), metric.WithInt64Callback(func(ctx context.Context, o metric.Int64Observer) error { - return callback(ctx, TaskStartedCounterObserver{o: o}) + return callback(ctx, TaskStartedObserver{o: o}) }), ) if err != nil { - return TaskStartedObservableCounter{}, fmt.Errorf("create the %s instrument: %w", "myapp.task.started", err) + return TaskStartedObservable{}, fmt.Errorf("create the %s instrument: %w", m.Name(), err) } - return TaskStartedObservableCounter{inst: inst}, nil + return TaskStartedObservable{inst: inst}, nil +} + +// Name returns the name `myapp.task.started` records under. +func (TaskStartedObservable) Name() string { + return TaskStarted{}.Name() +} + +// Unit returns the unit of `myapp.task.started`. +func (TaskStartedObservable) Unit() string { + return TaskStarted{}.Unit() +} + +// Description returns the description of `myapp.task.started`. +func (TaskStartedObservable) Description() string { + return TaskStarted{}.Description() +} + +// Inst returns the underlying metric.Int64ObservableCounter, or nil for the +// zero TaskStartedObservable. +func (m TaskStartedObservable) Inst() metric.Int64ObservableCounter { + return m.inst } diff --git a/templates/code/go/tests/metrics/expected/workermetric/metrics.go b/templates/code/go/tests/metrics/expected/workermetric/metrics.go index a297199..d4f6977 100644 --- a/templates/code/go/tests/metrics/expected/workermetric/metrics.go +++ b/templates/code/go/tests/metrics/expected/workermetric/metrics.go @@ -14,73 +14,92 @@ import ( "example.com/semconv/semconvmeter" ) -// TaskDurationHistogramAttr is an attribute `worker.task.duration` accepts -// in addition to the ones TaskDurationHistogram.Record requires. -type TaskDurationHistogramAttr interface { - taskDurationHistogramAttr() attribute.KeyValue +// TaskDurationAttr is an attribute `worker.task.duration` accepts in +// addition to the ones TaskDuration.Record requires. +type TaskDurationAttr interface { + taskDurationAttr() attribute.KeyValue } -type taskDurationHistogramMethod struct{ v authattr.MethodAttr } +type taskDurationMethod struct{ v authattr.Method } -func (o taskDurationHistogramMethod) taskDurationHistogramAttr() attribute.KeyValue { +func (o taskDurationMethod) taskDurationAttr() attribute.KeyValue { return o.v.KeyValue() } -// WithTaskDurationHistogramMethod attaches `auth.method` to -// TaskDurationHistogram. +// WithTaskDurationMethod attaches `auth.method` to TaskDuration. // // Opt-in: the convention records it only when a user asks for it. -func WithTaskDurationHistogramMethod(v authattr.MethodAttr) TaskDurationHistogramAttr { - return taskDurationHistogramMethod{v: v} +func WithTaskDurationMethod(v authattr.Method) TaskDurationAttr { + return taskDurationMethod{v: v} } -type taskDurationHistogramTaskState struct{ v myappattr.TaskStateAttr } +type taskDurationTaskState struct{ v myappattr.TaskState } -func (o taskDurationHistogramTaskState) taskDurationHistogramAttr() attribute.KeyValue { +func (o taskDurationTaskState) taskDurationAttr() attribute.KeyValue { return o.v.KeyValue() } -// WithTaskDurationHistogramTaskState attaches `myapp.task.state` to -// TaskDurationHistogram. +// WithTaskDurationTaskState attaches `myapp.task.state` to TaskDuration. // // Conditionally required: If the task reached a final state. -func WithTaskDurationHistogramTaskState(v myappattr.TaskStateAttr) TaskDurationHistogramAttr { - return taskDurationHistogramTaskState{v: v} +func WithTaskDurationTaskState(v myappattr.TaskState) TaskDurationAttr { + return taskDurationTaskState{v: v} } -// TaskDurationHistogram is `worker.task.duration`, a refinement of +// TaskDuration is `worker.task.duration`, a refinement of // `myapp.task.duration` that records under that metric's name. // // Time a task took on the worker that ran it. // // Measured by the worker that ran the task. -type TaskDurationHistogram struct{ inst metric.Float64Histogram } +type TaskDuration struct{ inst metric.Float64Histogram } -// NewTaskDurationHistogram creates the `myapp.task.duration` instrument from -// meter. -func NewTaskDurationHistogram(meter semconvmeter.Meter) (TaskDurationHistogram, error) { +// NewTaskDuration creates the `myapp.task.duration` instrument from meter. +func NewTaskDuration(meter semconvmeter.Meter) (TaskDuration, error) { + var m TaskDuration inst, err := meter.MetricMeter().Float64Histogram( - "myapp.task.duration", - metric.WithDescription("Time a task took from start to finish."), - metric.WithUnit("s"), + m.Name(), + metric.WithDescription(m.Description()), + metric.WithUnit(m.Unit()), metric.WithExplicitBucketBoundaries(0, 0.005, 0.01, 0.1, 1, 10), ) if err != nil { - return TaskDurationHistogram{}, fmt.Errorf("create the %s instrument: %w", "myapp.task.duration", err) + return TaskDuration{}, fmt.Errorf("create the %s instrument: %w", m.Name(), err) } - return TaskDurationHistogram{inst: inst}, nil + return TaskDuration{inst: inst}, nil +} + +// Name returns the name `worker.task.duration` records under. +func (TaskDuration) Name() string { + return "myapp.task.duration" +} + +// Unit returns the unit of `worker.task.duration`. +func (TaskDuration) Unit() string { + return "s" +} + +// Description returns the description of `worker.task.duration`. +func (TaskDuration) Description() string { + return "Time a task took from start to finish." +} + +// Inst returns the underlying metric.Float64Histogram, or nil for the zero +// TaskDuration. +func (m TaskDuration) Inst() metric.Float64Histogram { + return m.inst } // Record records one `worker.task.duration` measurement. The zero -// TaskDurationHistogram records nothing. -func (m TaskDurationHistogram) Record(ctx context.Context, value float64, myappTaskID myappattr.TaskIDAttr, opts ...TaskDurationHistogramAttr) { +// TaskDuration records nothing. +func (m TaskDuration) Record(ctx context.Context, value float64, myappTaskID myappattr.TaskID, opts ...TaskDurationAttr) { if m.inst == nil { return } kvs := make([]attribute.KeyValue, 0, 1+len(opts)) kvs = append(kvs, myappTaskID.KeyValue()) for _, opt := range opts { - kvs = append(kvs, opt.taskDurationHistogramAttr()) + kvs = append(kvs, opt.taskDurationAttr()) } m.inst.Record(ctx, value, metric.WithAttributes(kvs...)) } diff --git a/templates/code/go/tests/no_namespace/expected/exceptionattr/attributes.go b/templates/code/go/tests/no_namespace/expected/exceptionattr/attributes.go index 026f84d..cf02bff 100644 --- a/templates/code/go/tests/no_namespace/expected/exceptionattr/attributes.go +++ b/templates/code/go/tests/no_namespace/expected/exceptionattr/attributes.go @@ -7,45 +7,45 @@ import "go.opentelemetry.io/otel/attribute" // messageKey is the attribute key of `exception.message`. const messageKey = attribute.Key("exception.message") -// MessageAttr is a value of `exception.message`. +// Message is a value of `exception.message`. // // The exception message. -type MessageAttr struct{ value string } +type Message struct{ value string } -// NewMessageAttr returns a value of `exception.message`. -func NewMessageAttr(value string) MessageAttr { - return MessageAttr{value: value} +// NewMessage returns a value of `exception.message`. +func NewMessage(value string) Message { + return Message{value: value} } // Key is the attribute key, for filters and views that need it. -func (MessageAttr) Key() attribute.Key { +func (Message) Key() attribute.Key { return messageKey } // KeyValue is the `exception.message` attribute set to this value. -func (v MessageAttr) KeyValue() attribute.KeyValue { +func (v Message) KeyValue() attribute.KeyValue { return messageKey.String(v.value) } // typeKey is the attribute key of `exception.type`. const typeKey = attribute.Key("exception.type") -// TypeAttr is a value of `exception.type`. +// Type is a value of `exception.type`. // // The type of the exception. -type TypeAttr struct{ value string } +type Type struct{ value string } -// NewTypeAttr returns a value of `exception.type`. -func NewTypeAttr(value string) TypeAttr { - return TypeAttr{value: value} +// NewType returns a value of `exception.type`. +func NewType(value string) Type { + return Type{value: value} } // Key is the attribute key, for filters and views that need it. -func (TypeAttr) Key() attribute.Key { +func (Type) Key() attribute.Key { return typeKey } // KeyValue is the `exception.type` attribute set to this value. -func (v TypeAttr) KeyValue() attribute.KeyValue { +func (v Type) KeyValue() attribute.KeyValue { return typeKey.String(v.value) } diff --git a/templates/code/go/tests/no_namespace/expected/exceptionevent/events.go b/templates/code/go/tests/no_namespace/expected/exceptionevent/events.go index 4a91766..c7edba2 100644 --- a/templates/code/go/tests/no_namespace/expected/exceptionevent/events.go +++ b/templates/code/go/tests/no_namespace/expected/exceptionevent/events.go @@ -41,14 +41,14 @@ func WithTimestamp(timestamp time.Time) Option { return bareEventTimestamp{v: timestamp} } -type bareEventMessage struct{ v exceptionattr.MessageAttr } +type bareEventMessage struct{ v exceptionattr.Message } func (o bareEventMessage) bareOption(record *log.Record) { record.AddAttributes(o.v.KeyValue()) } // WithMessage sets `exception.message` on the event. -func WithMessage(v exceptionattr.MessageAttr) Option { +func WithMessage(v exceptionattr.Message) Option { return bareEventMessage{v: v} } @@ -56,7 +56,7 @@ func WithMessage(v exceptionattr.MessageAttr) Option { // is not enabled for it, and the zero logger emits nothing. // // A noteworthy exception occurred. -func Emit(ctx context.Context, logger semconvlogger.Logger, exceptionType exceptionattr.TypeAttr, opts ...Option) { +func Emit(ctx context.Context, logger semconvlogger.Logger, exceptionType exceptionattr.Type, opts ...Option) { var record log.Record record.SetEventName("exception") record.SetSeverity(log.SeverityInfo) diff --git a/templates/code/go/tests/no_namespace/expected/heartbeatattr/attributes.go b/templates/code/go/tests/no_namespace/expected/heartbeatattr/attributes.go index 28f8f64..760f10b 100644 --- a/templates/code/go/tests/no_namespace/expected/heartbeatattr/attributes.go +++ b/templates/code/go/tests/no_namespace/expected/heartbeatattr/attributes.go @@ -7,45 +7,45 @@ import "go.opentelemetry.io/otel/attribute" // sequenceKey is the attribute key of `heartbeat.sequence`. const sequenceKey = attribute.Key("heartbeat.sequence") -// SequenceAttr is a value of `heartbeat.sequence`. +// Sequence is a value of `heartbeat.sequence`. // // Sequence number of the heartbeat. -type SequenceAttr struct{ value int } +type Sequence struct{ value int } -// NewSequenceAttr returns a value of `heartbeat.sequence`. -func NewSequenceAttr(value int) SequenceAttr { - return SequenceAttr{value: value} +// NewSequence returns a value of `heartbeat.sequence`. +func NewSequence(value int) Sequence { + return Sequence{value: value} } // Key is the attribute key, for filters and views that need it. -func (SequenceAttr) Key() attribute.Key { +func (Sequence) Key() attribute.Key { return sequenceKey } // KeyValue is the `heartbeat.sequence` attribute set to this value. -func (v SequenceAttr) KeyValue() attribute.KeyValue { +func (v Sequence) KeyValue() attribute.KeyValue { return sequenceKey.Int(v.value) } // sourceKey is the attribute key of `heartbeat.source`. const sourceKey = attribute.Key("heartbeat.source") -// SourceAttr is a value of `heartbeat.source`. +// Source is a value of `heartbeat.source`. // // Name of the component that sent the heartbeat. -type SourceAttr struct{ value string } +type Source struct{ value string } -// NewSourceAttr returns a value of `heartbeat.source`. -func NewSourceAttr(value string) SourceAttr { - return SourceAttr{value: value} +// NewSource returns a value of `heartbeat.source`. +func NewSource(value string) Source { + return Source{value: value} } // Key is the attribute key, for filters and views that need it. -func (SourceAttr) Key() attribute.Key { +func (Source) Key() attribute.Key { return sourceKey } // KeyValue is the `heartbeat.source` attribute set to this value. -func (v SourceAttr) KeyValue() attribute.KeyValue { +func (v Source) KeyValue() attribute.KeyValue { return sourceKey.String(v.value) } diff --git a/templates/code/go/tests/no_namespace/expected/heartbeatspan/spans.go b/templates/code/go/tests/no_namespace/expected/heartbeatspan/spans.go index 7053b1a..974b986 100644 --- a/templates/code/go/tests/no_namespace/expected/heartbeatspan/spans.go +++ b/templates/code/go/tests/no_namespace/expected/heartbeatspan/spans.go @@ -27,7 +27,7 @@ type Attr interface { bareAttr() } -type bareSpanSource struct{ v heartbeatattr.SourceAttr } +type bareSpanSource struct{ v heartbeatattr.Source } func (o bareSpanSource) bareStartAttr() attribute.KeyValue { return o.v.KeyValue() @@ -37,7 +37,7 @@ func (bareSpanSource) bareAttr() {} // WithSource sets `heartbeat.source` on a Span, when Start starts it or // later through SetAttributes. -func WithSource(v heartbeatattr.SourceAttr) Attr { +func WithSource(v heartbeatattr.Source) Attr { return bareSpanSource{v: v} } @@ -91,7 +91,7 @@ func (s Span) SetStatus(code codes.Code, description string) { // Start starts the `heartbeat` span from tracer with span kind internal. // // A periodic liveness signal. -func Start(ctx context.Context, tracer semconvtracer.Tracer, name Name, heartbeatSequence heartbeatattr.SequenceAttr, opts ...StartAttr) (context.Context, Span) { +func Start(ctx context.Context, tracer semconvtracer.Tracer, name Name, heartbeatSequence heartbeatattr.Sequence, opts ...StartAttr) (context.Context, Span) { if name.value == "" { name = Name{value: "heartbeat"} } diff --git a/templates/code/go/tests/no_namespace/expected/hostattr/attributes.go b/templates/code/go/tests/no_namespace/expected/hostattr/attributes.go index cd170f1..b77ed58 100644 --- a/templates/code/go/tests/no_namespace/expected/hostattr/attributes.go +++ b/templates/code/go/tests/no_namespace/expected/hostattr/attributes.go @@ -7,45 +7,45 @@ import "go.opentelemetry.io/otel/attribute" // idKey is the attribute key of `host.id`. const idKey = attribute.Key("host.id") -// IDAttr is a value of `host.id`. +// ID is a value of `host.id`. // // Unique identifier of the host. -type IDAttr struct{ value string } +type ID struct{ value string } -// NewIDAttr returns a value of `host.id`. -func NewIDAttr(value string) IDAttr { - return IDAttr{value: value} +// NewID returns a value of `host.id`. +func NewID(value string) ID { + return ID{value: value} } // Key is the attribute key, for filters and views that need it. -func (IDAttr) Key() attribute.Key { +func (ID) Key() attribute.Key { return idKey } // KeyValue is the `host.id` attribute set to this value. -func (v IDAttr) KeyValue() attribute.KeyValue { +func (v ID) KeyValue() attribute.KeyValue { return idKey.String(v.value) } // nameKey is the attribute key of `host.name`. const nameKey = attribute.Key("host.name") -// NameAttr is a value of `host.name`. +// Name is a value of `host.name`. // // Name of the host. -type NameAttr struct{ value string } +type Name struct{ value string } -// NewNameAttr returns a value of `host.name`. -func NewNameAttr(value string) NameAttr { - return NameAttr{value: value} +// NewName returns a value of `host.name`. +func NewName(value string) Name { + return Name{value: value} } // Key is the attribute key, for filters and views that need it. -func (NameAttr) Key() attribute.Key { +func (Name) Key() attribute.Key { return nameKey } // KeyValue is the `host.name` attribute set to this value. -func (v NameAttr) KeyValue() attribute.KeyValue { +func (v Name) KeyValue() attribute.KeyValue { return nameKey.String(v.value) } diff --git a/templates/code/go/tests/no_namespace/expected/hostentity/entities.go b/templates/code/go/tests/no_namespace/expected/hostentity/entities.go index eed10e3..b1b9353 100644 --- a/templates/code/go/tests/no_namespace/expected/hostentity/entities.go +++ b/templates/code/go/tests/no_namespace/expected/hostentity/entities.go @@ -17,14 +17,14 @@ type EntityAttr interface { bareEntityAttr() attribute.KeyValue } -type bareEntityName struct{ v hostattr.NameAttr } +type bareEntityName struct{ v hostattr.Name } func (o bareEntityName) bareEntityAttr() attribute.KeyValue { return o.v.KeyValue() } // WithEntityName sets `host.name` on the entity. -func WithEntityName(v hostattr.NameAttr) EntityAttr { +func WithEntityName(v hostattr.Name) EntityAttr { return bareEntityName{v: v} } @@ -39,7 +39,7 @@ type Entity struct{ attrs []attribute.KeyValue } // NewEntity builds a Entity from its required attributes and any given // options. -func NewEntity(hostID hostattr.IDAttr, opts ...EntityAttr) Entity { +func NewEntity(hostID hostattr.ID, opts ...EntityAttr) Entity { attrs := make([]attribute.KeyValue, 0, 1+len(opts)) attrs = append(attrs, hostID.KeyValue()) for _, opt := range opts { diff --git a/templates/code/go/tests/params/expected/billingattr/attributes.go b/templates/code/go/tests/params/expected/billingattr/attributes.go index 6d9cc9d..521b7a5 100644 --- a/templates/code/go/tests/params/expected/billingattr/attributes.go +++ b/templates/code/go/tests/params/expected/billingattr/attributes.go @@ -8,45 +8,45 @@ import "go.opentelemetry.io/otel/attribute" // invoiceIDKey is the attribute key of `acme.billing.invoice.id`. const invoiceIDKey = attribute.Key("acme.billing.invoice.id") -// InvoiceIDAttr is a value of `acme.billing.invoice.id`. +// InvoiceID is a value of `acme.billing.invoice.id`. // // Identifier of the invoice. -type InvoiceIDAttr struct{ value string } +type InvoiceID struct{ value string } -// NewInvoiceIDAttr returns a value of `acme.billing.invoice.id`. -func NewInvoiceIDAttr(value string) InvoiceIDAttr { - return InvoiceIDAttr{value: value} +// NewInvoiceID returns a value of `acme.billing.invoice.id`. +func NewInvoiceID(value string) InvoiceID { + return InvoiceID{value: value} } // Key is the attribute key, for filters and views that need it. -func (InvoiceIDAttr) Key() attribute.Key { +func (InvoiceID) Key() attribute.Key { return invoiceIDKey } // KeyValue is the `acme.billing.invoice.id` attribute set to this value. -func (v InvoiceIDAttr) KeyValue() attribute.KeyValue { +func (v InvoiceID) KeyValue() attribute.KeyValue { return invoiceIDKey.String(v.value) } // currencyKey is the attribute key of `billing.currency`. const currencyKey = attribute.Key("billing.currency") -// CurrencyAttr is a value of `billing.currency`. +// Currency is a value of `billing.currency`. // // ISO 4217 currency code of the amount. -type CurrencyAttr struct{ value string } +type Currency struct{ value string } -// NewCurrencyAttr returns a value of `billing.currency`. -func NewCurrencyAttr(value string) CurrencyAttr { - return CurrencyAttr{value: value} +// NewCurrency returns a value of `billing.currency`. +func NewCurrency(value string) Currency { + return Currency{value: value} } // Key is the attribute key, for filters and views that need it. -func (CurrencyAttr) Key() attribute.Key { +func (Currency) Key() attribute.Key { return currencyKey } // KeyValue is the `billing.currency` attribute set to this value. -func (v CurrencyAttr) KeyValue() attribute.KeyValue { +func (v Currency) KeyValue() attribute.KeyValue { return currencyKey.String(v.value) } diff --git a/templates/code/go/tests/params/expected/billingmetric/metrics.go b/templates/code/go/tests/params/expected/billingmetric/metrics.go index 5ce2493..fee4d35 100644 --- a/templates/code/go/tests/params/expected/billingmetric/metrics.go +++ b/templates/code/go/tests/params/expected/billingmetric/metrics.go @@ -15,65 +15,85 @@ import ( "example.com/acme/internal/acmesemconv/myappattr" ) -// InvoiceAmountHistogramAttr is an attribute `acme.billing.invoice.amount` -// accepts in addition to the ones InvoiceAmountHistogram.Record requires. -type InvoiceAmountHistogramAttr interface { - invoiceAmountHistogramAttr() attribute.KeyValue +// InvoiceAmountAttr is an attribute `acme.billing.invoice.amount` accepts in +// addition to the ones InvoiceAmount.Record requires. +type InvoiceAmountAttr interface { + invoiceAmountAttr() attribute.KeyValue } -type invoiceAmountHistogramCurrency struct{ v billingattr.CurrencyAttr } +type invoiceAmountCurrency struct{ v billingattr.Currency } -func (o invoiceAmountHistogramCurrency) invoiceAmountHistogramAttr() attribute.KeyValue { +func (o invoiceAmountCurrency) invoiceAmountAttr() attribute.KeyValue { return o.v.KeyValue() } -// WithInvoiceAmountHistogramCurrency attaches `billing.currency` to -// InvoiceAmountHistogram. -func WithInvoiceAmountHistogramCurrency(v billingattr.CurrencyAttr) InvoiceAmountHistogramAttr { - return invoiceAmountHistogramCurrency{v: v} +// WithInvoiceAmountCurrency attaches `billing.currency` to InvoiceAmount. +func WithInvoiceAmountCurrency(v billingattr.Currency) InvoiceAmountAttr { + return invoiceAmountCurrency{v: v} } -type invoiceAmountHistogramRequestURL struct{ v myappattr.RequestURLAttr } +type invoiceAmountRequestURL struct{ v myappattr.RequestURL } -func (o invoiceAmountHistogramRequestURL) invoiceAmountHistogramAttr() attribute.KeyValue { +func (o invoiceAmountRequestURL) invoiceAmountAttr() attribute.KeyValue { return o.v.KeyValue() } -// WithInvoiceAmountHistogramRequestURL attaches `myapp.request.url` to -// InvoiceAmountHistogram. -func WithInvoiceAmountHistogramRequestURL(v myappattr.RequestURLAttr) InvoiceAmountHistogramAttr { - return invoiceAmountHistogramRequestURL{v: v} +// WithInvoiceAmountRequestURL attaches `myapp.request.url` to InvoiceAmount. +func WithInvoiceAmountRequestURL(v myappattr.RequestURL) InvoiceAmountAttr { + return invoiceAmountRequestURL{v: v} } -// InvoiceAmountHistogram is `acme.billing.invoice.amount`. +// InvoiceAmount is `acme.billing.invoice.amount`. // // Amount of each issued invoice. -type InvoiceAmountHistogram struct{ inst metric.Float64Histogram } +type InvoiceAmount struct{ inst metric.Float64Histogram } -// NewInvoiceAmountHistogram creates the `acme.billing.invoice.amount` -// instrument from meter. -func NewInvoiceAmountHistogram(meter acmesemconvmeter.Meter) (InvoiceAmountHistogram, error) { +// NewInvoiceAmount creates the `acme.billing.invoice.amount` instrument from +// meter. +func NewInvoiceAmount(meter acmesemconvmeter.Meter) (InvoiceAmount, error) { + var m InvoiceAmount inst, err := meter.MetricMeter().Float64Histogram( - "acme.billing.invoice.amount", - metric.WithDescription("Amount of each issued invoice."), - metric.WithUnit("{currency_unit}"), + m.Name(), + metric.WithDescription(m.Description()), + metric.WithUnit(m.Unit()), ) if err != nil { - return InvoiceAmountHistogram{}, fmt.Errorf("create the %s instrument: %w", "acme.billing.invoice.amount", err) + return InvoiceAmount{}, fmt.Errorf("create the %s instrument: %w", m.Name(), err) } - return InvoiceAmountHistogram{inst: inst}, nil + return InvoiceAmount{inst: inst}, nil +} + +// Name returns the name `acme.billing.invoice.amount` records under. +func (InvoiceAmount) Name() string { + return "acme.billing.invoice.amount" +} + +// Unit returns the unit of `acme.billing.invoice.amount`. +func (InvoiceAmount) Unit() string { + return "{currency_unit}" +} + +// Description returns the description of `acme.billing.invoice.amount`. +func (InvoiceAmount) Description() string { + return "Amount of each issued invoice." +} + +// Inst returns the underlying metric.Float64Histogram, or nil for the zero +// InvoiceAmount. +func (m InvoiceAmount) Inst() metric.Float64Histogram { + return m.inst } // Record records one `acme.billing.invoice.amount` measurement. The zero -// InvoiceAmountHistogram records nothing. -func (m InvoiceAmountHistogram) Record(ctx context.Context, value float64, billingInvoiceID billingattr.InvoiceIDAttr, opts ...InvoiceAmountHistogramAttr) { +// InvoiceAmount records nothing. +func (m InvoiceAmount) Record(ctx context.Context, value float64, billingInvoiceID billingattr.InvoiceID, opts ...InvoiceAmountAttr) { if m.inst == nil { return } kvs := make([]attribute.KeyValue, 0, 1+len(opts)) kvs = append(kvs, billingInvoiceID.KeyValue()) for _, opt := range opts { - kvs = append(kvs, opt.invoiceAmountHistogramAttr()) + kvs = append(kvs, opt.invoiceAmountAttr()) } m.inst.Record(ctx, value, metric.WithAttributes(kvs...)) } diff --git a/templates/code/go/tests/params/expected/myappattr/attributes.go b/templates/code/go/tests/params/expected/myappattr/attributes.go index 6d469a1..8a0c4fc 100644 --- a/templates/code/go/tests/params/expected/myappattr/attributes.go +++ b/templates/code/go/tests/params/expected/myappattr/attributes.go @@ -8,22 +8,22 @@ import "go.opentelemetry.io/otel/attribute" // requestURLKey is the attribute key of `myapp.request.url`. const requestURLKey = attribute.Key("myapp.request.url") -// RequestURLAttr is a value of `myapp.request.url`. +// RequestURL is a value of `myapp.request.url`. // // URL the request was sent to. -type RequestURLAttr struct{ value string } +type RequestURL struct{ value string } -// NewRequestURLAttr returns a value of `myapp.request.url`. -func NewRequestURLAttr(value string) RequestURLAttr { - return RequestURLAttr{value: value} +// NewRequestURL returns a value of `myapp.request.url`. +func NewRequestURL(value string) RequestURL { + return RequestURL{value: value} } // Key is the attribute key, for filters and views that need it. -func (RequestURLAttr) Key() attribute.Key { +func (RequestURL) Key() attribute.Key { return requestURLKey } // KeyValue is the `myapp.request.url` attribute set to this value. -func (v RequestURLAttr) KeyValue() attribute.KeyValue { +func (v RequestURL) KeyValue() attribute.KeyValue { return requestURLKey.String(v.value) } diff --git a/templates/code/go/tests/root_package_from_import_path/expected/myappattr/attributes.go b/templates/code/go/tests/root_package_from_import_path/expected/myappattr/attributes.go index e7ad465..a95aec9 100644 --- a/templates/code/go/tests/root_package_from_import_path/expected/myappattr/attributes.go +++ b/templates/code/go/tests/root_package_from_import_path/expected/myappattr/attributes.go @@ -7,22 +7,22 @@ import "go.opentelemetry.io/otel/attribute" // taskStateKey is the attribute key of `myapp.task.state`. const taskStateKey = attribute.Key("myapp.task.state") -// TaskStateAttr is a value of `myapp.task.state`. +// TaskState is a value of `myapp.task.state`. // // Current state of the task. -type TaskStateAttr struct{ value string } +type TaskState struct{ value string } -// NewTaskStateAttr returns a value of `myapp.task.state`. -func NewTaskStateAttr(value string) TaskStateAttr { - return TaskStateAttr{value: value} +// NewTaskState returns a value of `myapp.task.state`. +func NewTaskState(value string) TaskState { + return TaskState{value: value} } // Key is the attribute key, for filters and views that need it. -func (TaskStateAttr) Key() attribute.Key { +func (TaskState) Key() attribute.Key { return taskStateKey } // KeyValue is the `myapp.task.state` attribute set to this value. -func (v TaskStateAttr) KeyValue() attribute.KeyValue { +func (v TaskState) KeyValue() attribute.KeyValue { return taskStateKey.String(v.value) } diff --git a/templates/code/go/tests/root_package_from_import_path/expected/myappmetric/metrics.go b/templates/code/go/tests/root_package_from_import_path/expected/myappmetric/metrics.go index b7e21e1..e6e9ae8 100644 --- a/templates/code/go/tests/root_package_from_import_path/expected/myappmetric/metrics.go +++ b/templates/code/go/tests/root_package_from_import_path/expected/myappmetric/metrics.go @@ -13,28 +13,49 @@ import ( "example.com/acme/acmeconv/myappattr" ) -// TaskStartedCounter is `myapp.task.started`. +// TaskStarted is `myapp.task.started`. // // Number of tasks started. -type TaskStartedCounter struct{ inst metric.Int64Counter } +type TaskStarted struct{ inst metric.Int64Counter } -// NewTaskStartedCounter creates the `myapp.task.started` instrument from -// meter. -func NewTaskStartedCounter(meter acmeconvmeter.Meter) (TaskStartedCounter, error) { +// NewTaskStarted creates the `myapp.task.started` instrument from meter. +func NewTaskStarted(meter acmeconvmeter.Meter) (TaskStarted, error) { + var m TaskStarted inst, err := meter.MetricMeter().Int64Counter( - "myapp.task.started", - metric.WithDescription("Number of tasks started."), - metric.WithUnit("{task}"), + m.Name(), + metric.WithDescription(m.Description()), + metric.WithUnit(m.Unit()), ) if err != nil { - return TaskStartedCounter{}, fmt.Errorf("create the %s instrument: %w", "myapp.task.started", err) + return TaskStarted{}, fmt.Errorf("create the %s instrument: %w", m.Name(), err) } - return TaskStartedCounter{inst: inst}, nil + return TaskStarted{inst: inst}, nil } -// Add records one `myapp.task.started` measurement. The zero -// TaskStartedCounter records nothing. -func (m TaskStartedCounter) Add(ctx context.Context, incr int64, myappTaskState myappattr.TaskStateAttr) { +// Name returns the name `myapp.task.started` records under. +func (TaskStarted) Name() string { + return "myapp.task.started" +} + +// Unit returns the unit of `myapp.task.started`. +func (TaskStarted) Unit() string { + return "{task}" +} + +// Description returns the description of `myapp.task.started`. +func (TaskStarted) Description() string { + return "Number of tasks started." +} + +// Inst returns the underlying metric.Int64Counter, or nil for the zero +// TaskStarted. +func (m TaskStarted) Inst() metric.Int64Counter { + return m.inst +} + +// Add records one `myapp.task.started` measurement. The zero TaskStarted +// records nothing. +func (m TaskStarted) Add(ctx context.Context, incr int64, myappTaskState myappattr.TaskState) { if m.inst == nil { return } @@ -43,15 +64,15 @@ func (m TaskStartedCounter) Add(ctx context.Context, incr int64, myappTaskState m.inst.Add(ctx, incr, metric.WithAttributes(kvs...)) } -// TaskStartedCounterObserver records `myapp.task.started` observations from -// the callback of a TaskStartedObservableCounter. The zero -// TaskStartedCounterObserver records nothing. -type TaskStartedCounterObserver struct { +// TaskStartedObserver records `myapp.task.started` observations from the +// callback of a TaskStartedObservable. The zero TaskStartedObserver records +// nothing. +type TaskStartedObserver struct { o metric.Int64Observer } // Observe records one `myapp.task.started` observation. -func (o TaskStartedCounterObserver) Observe(value int64, myappTaskState myappattr.TaskStateAttr) { +func (o TaskStartedObserver) Observe(value int64, myappTaskState myappattr.TaskState) { if o.o == nil { return } @@ -60,36 +81,57 @@ func (o TaskStartedCounterObserver) Observe(value int64, myappTaskState myappatt o.o.Observe(value, metric.WithAttributes(kvs...)) } -// TaskStartedCounterCallback observes `myapp.task.started` through o on -// every collection of a TaskStartedObservableCounter. +// TaskStartedCallback observes `myapp.task.started` through o on every +// collection of a TaskStartedObservable. // // An error it returns is returned by the collection that ran it, and the // observations made before it returned are still recorded. -type TaskStartedCounterCallback func(ctx context.Context, o TaskStartedCounterObserver) error +type TaskStartedCallback func(ctx context.Context, o TaskStartedObserver) error -// TaskStartedObservableCounter is the asynchronous form of -// TaskStartedCounter, observed through the callback it was created with. -type TaskStartedObservableCounter struct { +// TaskStartedObservable is the asynchronous form of TaskStarted, observed +// through the callback it was created with. +type TaskStartedObservable struct { inst metric.Int64ObservableCounter } -// NewTaskStartedObservableCounter creates the `myapp.task.started` -// instrument from meter and registers callback to observe it on every -// collection. -func NewTaskStartedObservableCounter(meter acmeconvmeter.Meter, callback TaskStartedCounterCallback) (TaskStartedObservableCounter, error) { +// NewTaskStartedObservable creates the `myapp.task.started` instrument from +// meter and registers callback to observe it on every collection. +func NewTaskStartedObservable(meter acmeconvmeter.Meter, callback TaskStartedCallback) (TaskStartedObservable, error) { + var m TaskStartedObservable if callback == nil { - return TaskStartedObservableCounter{}, fmt.Errorf("create the %s instrument: the callback is nil", "myapp.task.started") + return TaskStartedObservable{}, fmt.Errorf("create the %s instrument: the callback is nil", m.Name()) } inst, err := meter.MetricMeter().Int64ObservableCounter( - "myapp.task.started", - metric.WithDescription("Number of tasks started."), - metric.WithUnit("{task}"), + m.Name(), + metric.WithDescription(m.Description()), + metric.WithUnit(m.Unit()), metric.WithInt64Callback(func(ctx context.Context, o metric.Int64Observer) error { - return callback(ctx, TaskStartedCounterObserver{o: o}) + return callback(ctx, TaskStartedObserver{o: o}) }), ) if err != nil { - return TaskStartedObservableCounter{}, fmt.Errorf("create the %s instrument: %w", "myapp.task.started", err) + return TaskStartedObservable{}, fmt.Errorf("create the %s instrument: %w", m.Name(), err) } - return TaskStartedObservableCounter{inst: inst}, nil + return TaskStartedObservable{inst: inst}, nil +} + +// Name returns the name `myapp.task.started` records under. +func (TaskStartedObservable) Name() string { + return TaskStarted{}.Name() +} + +// Unit returns the unit of `myapp.task.started`. +func (TaskStartedObservable) Unit() string { + return TaskStarted{}.Unit() +} + +// Description returns the description of `myapp.task.started`. +func (TaskStartedObservable) Description() string { + return TaskStarted{}.Description() +} + +// Inst returns the underlying metric.Int64ObservableCounter, or nil for the +// zero TaskStartedObservable. +func (m TaskStartedObservable) Inst() metric.Int64ObservableCounter { + return m.inst } diff --git a/templates/code/go/tests/root_package_version_segment/expected/myappattr/attributes.go b/templates/code/go/tests/root_package_version_segment/expected/myappattr/attributes.go index e7ad465..a95aec9 100644 --- a/templates/code/go/tests/root_package_version_segment/expected/myappattr/attributes.go +++ b/templates/code/go/tests/root_package_version_segment/expected/myappattr/attributes.go @@ -7,22 +7,22 @@ import "go.opentelemetry.io/otel/attribute" // taskStateKey is the attribute key of `myapp.task.state`. const taskStateKey = attribute.Key("myapp.task.state") -// TaskStateAttr is a value of `myapp.task.state`. +// TaskState is a value of `myapp.task.state`. // // Current state of the task. -type TaskStateAttr struct{ value string } +type TaskState struct{ value string } -// NewTaskStateAttr returns a value of `myapp.task.state`. -func NewTaskStateAttr(value string) TaskStateAttr { - return TaskStateAttr{value: value} +// NewTaskState returns a value of `myapp.task.state`. +func NewTaskState(value string) TaskState { + return TaskState{value: value} } // Key is the attribute key, for filters and views that need it. -func (TaskStateAttr) Key() attribute.Key { +func (TaskState) Key() attribute.Key { return taskStateKey } // KeyValue is the `myapp.task.state` attribute set to this value. -func (v TaskStateAttr) KeyValue() attribute.KeyValue { +func (v TaskState) KeyValue() attribute.KeyValue { return taskStateKey.String(v.value) } diff --git a/templates/code/go/tests/root_package_version_segment/expected/myappmetric/metrics.go b/templates/code/go/tests/root_package_version_segment/expected/myappmetric/metrics.go index c68bbdc..7f6562c 100644 --- a/templates/code/go/tests/root_package_version_segment/expected/myappmetric/metrics.go +++ b/templates/code/go/tests/root_package_version_segment/expected/myappmetric/metrics.go @@ -13,28 +13,49 @@ import ( "example.com/acme/acmeconv/v1.2.0/myappattr" ) -// TaskStartedCounter is `myapp.task.started`. +// TaskStarted is `myapp.task.started`. // // Number of tasks started. -type TaskStartedCounter struct{ inst metric.Int64Counter } +type TaskStarted struct{ inst metric.Int64Counter } -// NewTaskStartedCounter creates the `myapp.task.started` instrument from -// meter. -func NewTaskStartedCounter(meter acmeconvmeter.Meter) (TaskStartedCounter, error) { +// NewTaskStarted creates the `myapp.task.started` instrument from meter. +func NewTaskStarted(meter acmeconvmeter.Meter) (TaskStarted, error) { + var m TaskStarted inst, err := meter.MetricMeter().Int64Counter( - "myapp.task.started", - metric.WithDescription("Number of tasks started."), - metric.WithUnit("{task}"), + m.Name(), + metric.WithDescription(m.Description()), + metric.WithUnit(m.Unit()), ) if err != nil { - return TaskStartedCounter{}, fmt.Errorf("create the %s instrument: %w", "myapp.task.started", err) + return TaskStarted{}, fmt.Errorf("create the %s instrument: %w", m.Name(), err) } - return TaskStartedCounter{inst: inst}, nil + return TaskStarted{inst: inst}, nil } -// Add records one `myapp.task.started` measurement. The zero -// TaskStartedCounter records nothing. -func (m TaskStartedCounter) Add(ctx context.Context, incr int64, myappTaskState myappattr.TaskStateAttr) { +// Name returns the name `myapp.task.started` records under. +func (TaskStarted) Name() string { + return "myapp.task.started" +} + +// Unit returns the unit of `myapp.task.started`. +func (TaskStarted) Unit() string { + return "{task}" +} + +// Description returns the description of `myapp.task.started`. +func (TaskStarted) Description() string { + return "Number of tasks started." +} + +// Inst returns the underlying metric.Int64Counter, or nil for the zero +// TaskStarted. +func (m TaskStarted) Inst() metric.Int64Counter { + return m.inst +} + +// Add records one `myapp.task.started` measurement. The zero TaskStarted +// records nothing. +func (m TaskStarted) Add(ctx context.Context, incr int64, myappTaskState myappattr.TaskState) { if m.inst == nil { return } @@ -43,15 +64,15 @@ func (m TaskStartedCounter) Add(ctx context.Context, incr int64, myappTaskState m.inst.Add(ctx, incr, metric.WithAttributes(kvs...)) } -// TaskStartedCounterObserver records `myapp.task.started` observations from -// the callback of a TaskStartedObservableCounter. The zero -// TaskStartedCounterObserver records nothing. -type TaskStartedCounterObserver struct { +// TaskStartedObserver records `myapp.task.started` observations from the +// callback of a TaskStartedObservable. The zero TaskStartedObserver records +// nothing. +type TaskStartedObserver struct { o metric.Int64Observer } // Observe records one `myapp.task.started` observation. -func (o TaskStartedCounterObserver) Observe(value int64, myappTaskState myappattr.TaskStateAttr) { +func (o TaskStartedObserver) Observe(value int64, myappTaskState myappattr.TaskState) { if o.o == nil { return } @@ -60,36 +81,57 @@ func (o TaskStartedCounterObserver) Observe(value int64, myappTaskState myappatt o.o.Observe(value, metric.WithAttributes(kvs...)) } -// TaskStartedCounterCallback observes `myapp.task.started` through o on -// every collection of a TaskStartedObservableCounter. +// TaskStartedCallback observes `myapp.task.started` through o on every +// collection of a TaskStartedObservable. // // An error it returns is returned by the collection that ran it, and the // observations made before it returned are still recorded. -type TaskStartedCounterCallback func(ctx context.Context, o TaskStartedCounterObserver) error +type TaskStartedCallback func(ctx context.Context, o TaskStartedObserver) error -// TaskStartedObservableCounter is the asynchronous form of -// TaskStartedCounter, observed through the callback it was created with. -type TaskStartedObservableCounter struct { +// TaskStartedObservable is the asynchronous form of TaskStarted, observed +// through the callback it was created with. +type TaskStartedObservable struct { inst metric.Int64ObservableCounter } -// NewTaskStartedObservableCounter creates the `myapp.task.started` -// instrument from meter and registers callback to observe it on every -// collection. -func NewTaskStartedObservableCounter(meter acmeconvmeter.Meter, callback TaskStartedCounterCallback) (TaskStartedObservableCounter, error) { +// NewTaskStartedObservable creates the `myapp.task.started` instrument from +// meter and registers callback to observe it on every collection. +func NewTaskStartedObservable(meter acmeconvmeter.Meter, callback TaskStartedCallback) (TaskStartedObservable, error) { + var m TaskStartedObservable if callback == nil { - return TaskStartedObservableCounter{}, fmt.Errorf("create the %s instrument: the callback is nil", "myapp.task.started") + return TaskStartedObservable{}, fmt.Errorf("create the %s instrument: the callback is nil", m.Name()) } inst, err := meter.MetricMeter().Int64ObservableCounter( - "myapp.task.started", - metric.WithDescription("Number of tasks started."), - metric.WithUnit("{task}"), + m.Name(), + metric.WithDescription(m.Description()), + metric.WithUnit(m.Unit()), metric.WithInt64Callback(func(ctx context.Context, o metric.Int64Observer) error { - return callback(ctx, TaskStartedCounterObserver{o: o}) + return callback(ctx, TaskStartedObserver{o: o}) }), ) if err != nil { - return TaskStartedObservableCounter{}, fmt.Errorf("create the %s instrument: %w", "myapp.task.started", err) + return TaskStartedObservable{}, fmt.Errorf("create the %s instrument: %w", m.Name(), err) } - return TaskStartedObservableCounter{inst: inst}, nil + return TaskStartedObservable{inst: inst}, nil +} + +// Name returns the name `myapp.task.started` records under. +func (TaskStartedObservable) Name() string { + return TaskStarted{}.Name() +} + +// Unit returns the unit of `myapp.task.started`. +func (TaskStartedObservable) Unit() string { + return TaskStarted{}.Unit() +} + +// Description returns the description of `myapp.task.started`. +func (TaskStartedObservable) Description() string { + return TaskStarted{}.Description() +} + +// Inst returns the underlying metric.Int64ObservableCounter, or nil for the +// zero TaskStartedObservable. +func (m TaskStartedObservable) Inst() metric.Int64ObservableCounter { + return m.inst } diff --git a/templates/code/go/tests/spans/expected/myappattr/attributes.go b/templates/code/go/tests/spans/expected/myappattr/attributes.go index 436faed..604f7de 100644 --- a/templates/code/go/tests/spans/expected/myappattr/attributes.go +++ b/templates/code/go/tests/spans/expected/myappattr/attributes.go @@ -7,87 +7,87 @@ import "go.opentelemetry.io/otel/attribute" // queueNameKey is the attribute key of `myapp.queue.name`. const queueNameKey = attribute.Key("myapp.queue.name") -// QueueNameAttr is a value of `myapp.queue.name`. +// QueueName is a value of `myapp.queue.name`. // // Name of the queue the task came from. -type QueueNameAttr struct{ value string } +type QueueName struct{ value string } -// NewQueueNameAttr returns a value of `myapp.queue.name`. -func NewQueueNameAttr(value string) QueueNameAttr { - return QueueNameAttr{value: value} +// NewQueueName returns a value of `myapp.queue.name`. +func NewQueueName(value string) QueueName { + return QueueName{value: value} } // Key is the attribute key, for filters and views that need it. -func (QueueNameAttr) Key() attribute.Key { +func (QueueName) Key() attribute.Key { return queueNameKey } // KeyValue is the `myapp.queue.name` attribute set to this value. -func (v QueueNameAttr) KeyValue() attribute.KeyValue { +func (v QueueName) KeyValue() attribute.KeyValue { return queueNameKey.String(v.value) } // taskAttemptKey is the attribute key of `myapp.task.attempt`. const taskAttemptKey = attribute.Key("myapp.task.attempt") -// TaskAttemptAttr is a value of `myapp.task.attempt`. +// TaskAttempt is a value of `myapp.task.attempt`. // // Number of the attempt, starting at one. -type TaskAttemptAttr struct{ value int } +type TaskAttempt struct{ value int } -// NewTaskAttemptAttr returns a value of `myapp.task.attempt`. -func NewTaskAttemptAttr(value int) TaskAttemptAttr { - return TaskAttemptAttr{value: value} +// NewTaskAttempt returns a value of `myapp.task.attempt`. +func NewTaskAttempt(value int) TaskAttempt { + return TaskAttempt{value: value} } // Key is the attribute key, for filters and views that need it. -func (TaskAttemptAttr) Key() attribute.Key { +func (TaskAttempt) Key() attribute.Key { return taskAttemptKey } // KeyValue is the `myapp.task.attempt` attribute set to this value. -func (v TaskAttemptAttr) KeyValue() attribute.KeyValue { +func (v TaskAttempt) KeyValue() attribute.KeyValue { return taskAttemptKey.Int(v.value) } // taskIDKey is the attribute key of `myapp.task.id`. const taskIDKey = attribute.Key("myapp.task.id") -// TaskIDAttr is a value of `myapp.task.id`. +// TaskID is a value of `myapp.task.id`. // // Unique identifier of the task. -type TaskIDAttr struct{ value string } +type TaskID struct{ value string } -// NewTaskIDAttr returns a value of `myapp.task.id`. -func NewTaskIDAttr(value string) TaskIDAttr { - return TaskIDAttr{value: value} +// NewTaskID returns a value of `myapp.task.id`. +func NewTaskID(value string) TaskID { + return TaskID{value: value} } // Key is the attribute key, for filters and views that need it. -func (TaskIDAttr) Key() attribute.Key { +func (TaskID) Key() attribute.Key { return taskIDKey } // KeyValue is the `myapp.task.id` attribute set to this value. -func (v TaskIDAttr) KeyValue() attribute.KeyValue { +func (v TaskID) KeyValue() attribute.KeyValue { return taskIDKey.String(v.value) } // taskStateKey is the attribute key of `myapp.task.state`. const taskStateKey = attribute.Key("myapp.task.state") -// TaskStateAttr is a value of `myapp.task.state`. +// TaskState is a value of `myapp.task.state`. // // Current state of the task. -type TaskStateAttr struct{ value string } +type TaskState struct{ value string } // Key is the attribute key, for filters and views that need it. -func (TaskStateAttr) Key() attribute.Key { +func (TaskState) Key() attribute.Key { return taskStateKey } // KeyValue is the `myapp.task.state` attribute set to this value. -func (v TaskStateAttr) KeyValue() attribute.KeyValue { +func (v TaskState) KeyValue() attribute.KeyValue { return taskStateKey.String(v.value) } @@ -95,10 +95,10 @@ var ( // TaskStateQueued is the "queued" member of `myapp.task.state`. // // The task is waiting to run. - TaskStateQueued = TaskStateAttr{value: "queued"} + TaskStateQueued = TaskState{value: "queued"} // TaskStateDone is the "done" member of `myapp.task.state`. // // The task finished. - TaskStateDone = TaskStateAttr{value: "done"} + TaskStateDone = TaskState{value: "done"} ) diff --git a/templates/code/go/tests/spans/expected/myappspan/spans.go b/templates/code/go/tests/spans/expected/myappspan/spans.go index 0533be1..425d925 100644 --- a/templates/code/go/tests/spans/expected/myappspan/spans.go +++ b/templates/code/go/tests/spans/expected/myappspan/spans.go @@ -28,15 +28,15 @@ func NewQueueDrainName(name string) QueueDrainName { return QueueDrainName{value: name} } -// QueueDrainSpan is a started span of `myapp.queue.drain`. The zero -// QueueDrainSpan records nothing. +// QueueDrain is a started span of `myapp.queue.drain`. The zero QueueDrain +// records nothing. // // Deprecated: Drain queues by dispatching their tasks instead. -type QueueDrainSpan struct{ span trace.Span } +type QueueDrain struct{ span trace.Span } // Span returns the underlying trace.Span, or a no-op one for the zero -// QueueDrainSpan. -func (s QueueDrainSpan) Span() trace.Span { +// QueueDrain. +func (s QueueDrain) Span() trace.Span { if s.span == nil { return noop.Span{} } @@ -44,17 +44,17 @@ func (s QueueDrainSpan) Span() trace.Span { } // End ends the span. -func (s QueueDrainSpan) End(opts ...trace.SpanEndOption) { +func (s QueueDrain) End(opts ...trace.SpanEndOption) { s.Span().End(opts...) } // RecordError records err as an exception event on the span. -func (s QueueDrainSpan) RecordError(err error, opts ...trace.EventOption) { +func (s QueueDrain) RecordError(err error, opts ...trace.EventOption) { s.Span().RecordError(err, opts...) } // SetStatus sets the status of the span. -func (s QueueDrainSpan) SetStatus(code codes.Code, description string) { +func (s QueueDrain) SetStatus(code codes.Code, description string) { s.Span().SetStatus(code, description) } @@ -67,7 +67,7 @@ func (s QueueDrainSpan) SetStatus(code codes.Code, description string) { // for it. // // Deprecated: Drain queues by dispatching their tasks instead. -func StartQueueDrain(ctx context.Context, tracer semconvtracer.Tracer, name QueueDrainName) (context.Context, QueueDrainSpan) { +func StartQueueDrain(ctx context.Context, tracer semconvtracer.Tracer, name QueueDrainName) (context.Context, QueueDrain) { if name.value == "" { name = QueueDrainName{value: "myapp.queue.drain"} } @@ -76,7 +76,7 @@ func StartQueueDrain(ctx context.Context, tracer semconvtracer.Tracer, name Queu name.value, trace.WithSpanKind(trace.SpanKindConsumer), ) - return ctx, QueueDrainSpan{span: span} + return ctx, QueueDrain{span: span} } // TaskDispatchStartAttr is an attribute StartTaskDispatch accepts in @@ -85,14 +85,14 @@ type TaskDispatchStartAttr interface { taskDispatchStartAttr() attribute.KeyValue } -// TaskDispatchAttr is an attribute a TaskDispatchSpan also accepts after it +// TaskDispatchAttr is an attribute a TaskDispatch also accepts after it // started, through SetAttributes. type TaskDispatchAttr interface { TaskDispatchStartAttr taskDispatchAttr() } -type taskDispatchSpanQueueName struct{ v myappattr.QueueNameAttr } +type taskDispatchSpanQueueName struct{ v myappattr.QueueName } func (o taskDispatchSpanQueueName) taskDispatchStartAttr() attribute.KeyValue { return o.v.KeyValue() @@ -100,15 +100,15 @@ func (o taskDispatchSpanQueueName) taskDispatchStartAttr() attribute.KeyValue { func (taskDispatchSpanQueueName) taskDispatchAttr() {} -// WithTaskDispatchQueueName sets `myapp.queue.name` on a TaskDispatchSpan, -// when StartTaskDispatch starts it or later through SetAttributes. +// WithTaskDispatchQueueName sets `myapp.queue.name` on a TaskDispatch, when +// StartTaskDispatch starts it or later through SetAttributes. // // Recommended: When the task came from a named queue. -func WithTaskDispatchQueueName(v myappattr.QueueNameAttr) TaskDispatchAttr { +func WithTaskDispatchQueueName(v myappattr.QueueName) TaskDispatchAttr { return taskDispatchSpanQueueName{v: v} } -type taskDispatchSpanTaskAttempt struct{ v myappattr.TaskAttemptAttr } +type taskDispatchSpanTaskAttempt struct{ v myappattr.TaskAttempt } func (o taskDispatchSpanTaskAttempt) taskDispatchStartAttr() attribute.KeyValue { return o.v.KeyValue() @@ -116,16 +116,15 @@ func (o taskDispatchSpanTaskAttempt) taskDispatchStartAttr() attribute.KeyValue func (taskDispatchSpanTaskAttempt) taskDispatchAttr() {} -// WithTaskDispatchTaskAttempt sets `myapp.task.attempt` on a -// TaskDispatchSpan, when StartTaskDispatch starts it or later through -// SetAttributes. +// WithTaskDispatchTaskAttempt sets `myapp.task.attempt` on a TaskDispatch, +// when StartTaskDispatch starts it or later through SetAttributes. // // Opt-in: the convention records it only when a user asks for it. -func WithTaskDispatchTaskAttempt(v myappattr.TaskAttemptAttr) TaskDispatchAttr { +func WithTaskDispatchTaskAttempt(v myappattr.TaskAttempt) TaskDispatchAttr { return taskDispatchSpanTaskAttempt{v: v} } -type taskDispatchSpanTaskID struct{ v myappattr.TaskIDAttr } +type taskDispatchSpanTaskID struct{ v myappattr.TaskID } func (o taskDispatchSpanTaskID) taskDispatchStartAttr() attribute.KeyValue { return o.v.KeyValue() @@ -133,17 +132,17 @@ func (o taskDispatchSpanTaskID) taskDispatchStartAttr() attribute.KeyValue { // WithTaskDispatchTaskID sets `myapp.task.id` when StartTaskDispatch starts // the span. Samplers read it, so it is accepted only at start. -func WithTaskDispatchTaskID(v myappattr.TaskIDAttr) TaskDispatchStartAttr { +func WithTaskDispatchTaskID(v myappattr.TaskID) TaskDispatchStartAttr { return taskDispatchSpanTaskID{v: v} } -// TaskDispatchSpan is a started span of `myapp.task.dispatch`. The zero -// TaskDispatchSpan records nothing. -type TaskDispatchSpan struct{ span trace.Span } +// TaskDispatch is a started span of `myapp.task.dispatch`. The zero +// TaskDispatch records nothing. +type TaskDispatch struct{ span trace.Span } // Span returns the underlying trace.Span, or a no-op one for the zero -// TaskDispatchSpan. -func (s TaskDispatchSpan) Span() trace.Span { +// TaskDispatch. +func (s TaskDispatch) Span() trace.Span { if s.span == nil { return noop.Span{} } @@ -151,12 +150,12 @@ func (s TaskDispatchSpan) Span() trace.Span { } // End ends the span. -func (s TaskDispatchSpan) End(opts ...trace.SpanEndOption) { +func (s TaskDispatch) End(opts ...trace.SpanEndOption) { s.Span().End(opts...) } // SetAttributes sets attributes on the span after it started. -func (s TaskDispatchSpan) SetAttributes(attrs ...TaskDispatchAttr) { +func (s TaskDispatch) SetAttributes(attrs ...TaskDispatchAttr) { kvs := make([]attribute.KeyValue, 0, len(attrs)) for _, attr := range attrs { kvs = append(kvs, attr.taskDispatchStartAttr()) @@ -165,12 +164,12 @@ func (s TaskDispatchSpan) SetAttributes(attrs ...TaskDispatchAttr) { } // RecordError records err as an exception event on the span. -func (s TaskDispatchSpan) RecordError(err error, opts ...trace.EventOption) { +func (s TaskDispatch) RecordError(err error, opts ...trace.EventOption) { s.Span().RecordError(err, opts...) } // SetStatus sets the status of the span. -func (s TaskDispatchSpan) SetStatus(code codes.Code, description string) { +func (s TaskDispatch) SetStatus(code codes.Code, description string) { s.Span().SetStatus(code, description) } @@ -183,7 +182,7 @@ func (s TaskDispatchSpan) SetStatus(code codes.Code, description string) { // // The span is named `dispatch {worker.host.name}:{worker.host.port}`, with // each placeholder replaced by the value of the attribute it names. -func StartTaskDispatch(ctx context.Context, tracer semconvtracer.Tracer, workerHostName workerattr.HostNameAttr, workerHostPort workerattr.HostPortAttr, opts ...TaskDispatchStartAttr) (context.Context, TaskDispatchSpan) { +func StartTaskDispatch(ctx context.Context, tracer semconvtracer.Tracer, workerHostName workerattr.HostName, workerHostPort workerattr.HostPort, opts ...TaskDispatchStartAttr) (context.Context, TaskDispatch) { kvs := make([]attribute.KeyValue, 0, 2+len(opts)) kvs = append(kvs, workerHostName.KeyValue()) kvs = append(kvs, workerHostPort.KeyValue()) @@ -197,7 +196,7 @@ func StartTaskDispatch(ctx context.Context, tracer semconvtracer.Tracer, workerH trace.WithSpanKind(trace.SpanKindClient), trace.WithAttributes(kvs...), ) - return ctx, TaskDispatchSpan{span: span} + return ctx, TaskDispatch{span: span} } // TaskRunStartAttr is an attribute StartTaskRun accepts in addition to the @@ -206,14 +205,14 @@ type TaskRunStartAttr interface { taskRunStartAttr() attribute.KeyValue } -// TaskRunAttr is an attribute a TaskRunSpan also accepts after it started, +// TaskRunAttr is an attribute a TaskRun also accepts after it started, // through SetAttributes. type TaskRunAttr interface { TaskRunStartAttr taskRunAttr() } -type taskRunSpanTaskID struct{ v myappattr.TaskIDAttr } +type taskRunSpanTaskID struct{ v myappattr.TaskID } func (o taskRunSpanTaskID) taskRunStartAttr() attribute.KeyValue { return o.v.KeyValue() @@ -221,9 +220,9 @@ func (o taskRunSpanTaskID) taskRunStartAttr() attribute.KeyValue { func (taskRunSpanTaskID) taskRunAttr() {} -// WithTaskRunTaskID sets `myapp.task.id` on a TaskRunSpan, when StartTaskRun +// WithTaskRunTaskID sets `myapp.task.id` on a TaskRun, when StartTaskRun // starts it or later through SetAttributes. -func WithTaskRunTaskID(v myappattr.TaskIDAttr) TaskRunAttr { +func WithTaskRunTaskID(v myappattr.TaskID) TaskRunAttr { return taskRunSpanTaskID{v: v} } @@ -240,13 +239,13 @@ func NewTaskRunName(name string) TaskRunName { return TaskRunName{value: name} } -// TaskRunSpan is a started span of `myapp.task.run`. The zero TaskRunSpan -// records nothing. -type TaskRunSpan struct{ span trace.Span } +// TaskRun is a started span of `myapp.task.run`. The zero TaskRun records +// nothing. +type TaskRun struct{ span trace.Span } // Span returns the underlying trace.Span, or a no-op one for the zero -// TaskRunSpan. -func (s TaskRunSpan) Span() trace.Span { +// TaskRun. +func (s TaskRun) Span() trace.Span { if s.span == nil { return noop.Span{} } @@ -254,12 +253,12 @@ func (s TaskRunSpan) Span() trace.Span { } // End ends the span. -func (s TaskRunSpan) End(opts ...trace.SpanEndOption) { +func (s TaskRun) End(opts ...trace.SpanEndOption) { s.Span().End(opts...) } // SetAttributes sets attributes on the span after it started. -func (s TaskRunSpan) SetAttributes(attrs ...TaskRunAttr) { +func (s TaskRun) SetAttributes(attrs ...TaskRunAttr) { kvs := make([]attribute.KeyValue, 0, len(attrs)) for _, attr := range attrs { kvs = append(kvs, attr.taskRunStartAttr()) @@ -268,12 +267,12 @@ func (s TaskRunSpan) SetAttributes(attrs ...TaskRunAttr) { } // RecordError records err as an exception event on the span. -func (s TaskRunSpan) RecordError(err error, opts ...trace.EventOption) { +func (s TaskRun) RecordError(err error, opts ...trace.EventOption) { s.Span().RecordError(err, opts...) } // SetStatus sets the status of the span. -func (s TaskRunSpan) SetStatus(code codes.Code, description string) { +func (s TaskRun) SetStatus(code codes.Code, description string) { s.Span().SetStatus(code, description) } @@ -281,7 +280,7 @@ func (s TaskRunSpan) SetStatus(code codes.Code, description string) { // internal. // // One run of a task. -func StartTaskRun(ctx context.Context, tracer semconvtracer.Tracer, name TaskRunName, myappTaskState myappattr.TaskStateAttr, opts ...TaskRunStartAttr) (context.Context, TaskRunSpan) { +func StartTaskRun(ctx context.Context, tracer semconvtracer.Tracer, name TaskRunName, myappTaskState myappattr.TaskState, opts ...TaskRunStartAttr) (context.Context, TaskRun) { if name.value == "" { name = TaskRunName{value: "myapp.task.run"} } @@ -296,5 +295,5 @@ func StartTaskRun(ctx context.Context, tracer semconvtracer.Tracer, name TaskRun trace.WithSpanKind(trace.SpanKindInternal), trace.WithAttributes(kvs...), ) - return ctx, TaskRunSpan{span: span} + return ctx, TaskRun{span: span} } diff --git a/templates/code/go/tests/spans/expected/workerattr/attributes.go b/templates/code/go/tests/spans/expected/workerattr/attributes.go index 38931df..dadad08 100644 --- a/templates/code/go/tests/spans/expected/workerattr/attributes.go +++ b/templates/code/go/tests/spans/expected/workerattr/attributes.go @@ -7,45 +7,45 @@ import "go.opentelemetry.io/otel/attribute" // hostNameKey is the attribute key of `worker.host.name`. const hostNameKey = attribute.Key("worker.host.name") -// HostNameAttr is a value of `worker.host.name`. +// HostName is a value of `worker.host.name`. // // Host name of the worker. -type HostNameAttr struct{ value string } +type HostName struct{ value string } -// NewHostNameAttr returns a value of `worker.host.name`. -func NewHostNameAttr(value string) HostNameAttr { - return HostNameAttr{value: value} +// NewHostName returns a value of `worker.host.name`. +func NewHostName(value string) HostName { + return HostName{value: value} } // Key is the attribute key, for filters and views that need it. -func (HostNameAttr) Key() attribute.Key { +func (HostName) Key() attribute.Key { return hostNameKey } // KeyValue is the `worker.host.name` attribute set to this value. -func (v HostNameAttr) KeyValue() attribute.KeyValue { +func (v HostName) KeyValue() attribute.KeyValue { return hostNameKey.String(v.value) } // hostPortKey is the attribute key of `worker.host.port`. const hostPortKey = attribute.Key("worker.host.port") -// HostPortAttr is a value of `worker.host.port`. +// HostPort is a value of `worker.host.port`. // // Port the worker listens on. -type HostPortAttr struct{ value int } +type HostPort struct{ value int } -// NewHostPortAttr returns a value of `worker.host.port`. -func NewHostPortAttr(value int) HostPortAttr { - return HostPortAttr{value: value} +// NewHostPort returns a value of `worker.host.port`. +func NewHostPort(value int) HostPort { + return HostPort{value: value} } // Key is the attribute key, for filters and views that need it. -func (HostPortAttr) Key() attribute.Key { +func (HostPort) Key() attribute.Key { return hostPortKey } // KeyValue is the `worker.host.port` attribute set to this value. -func (v HostPortAttr) KeyValue() attribute.KeyValue { +func (v HostPort) KeyValue() attribute.KeyValue { return hostPortKey.Int(v.value) } diff --git a/templates/code/go/tests/spans/expected/workerspan/spans.go b/templates/code/go/tests/spans/expected/workerspan/spans.go index d62b93a..46ee6bc 100644 --- a/templates/code/go/tests/spans/expected/workerspan/spans.go +++ b/templates/code/go/tests/spans/expected/workerspan/spans.go @@ -21,14 +21,14 @@ type TaskDispatchStartAttr interface { taskDispatchStartAttr() attribute.KeyValue } -// TaskDispatchAttr is an attribute a TaskDispatchSpan also accepts after it +// TaskDispatchAttr is an attribute a TaskDispatch also accepts after it // started, through SetAttributes. type TaskDispatchAttr interface { TaskDispatchStartAttr taskDispatchAttr() } -type taskDispatchSpanQueueName struct{ v myappattr.QueueNameAttr } +type taskDispatchSpanQueueName struct{ v myappattr.QueueName } func (o taskDispatchSpanQueueName) taskDispatchStartAttr() attribute.KeyValue { return o.v.KeyValue() @@ -36,15 +36,15 @@ func (o taskDispatchSpanQueueName) taskDispatchStartAttr() attribute.KeyValue { func (taskDispatchSpanQueueName) taskDispatchAttr() {} -// WithTaskDispatchQueueName sets `myapp.queue.name` on a TaskDispatchSpan, -// when StartTaskDispatch starts it or later through SetAttributes. +// WithTaskDispatchQueueName sets `myapp.queue.name` on a TaskDispatch, when +// StartTaskDispatch starts it or later through SetAttributes. // // Recommended: When the task came from a named queue. -func WithTaskDispatchQueueName(v myappattr.QueueNameAttr) TaskDispatchAttr { +func WithTaskDispatchQueueName(v myappattr.QueueName) TaskDispatchAttr { return taskDispatchSpanQueueName{v: v} } -type taskDispatchSpanTaskID struct{ v myappattr.TaskIDAttr } +type taskDispatchSpanTaskID struct{ v myappattr.TaskID } func (o taskDispatchSpanTaskID) taskDispatchStartAttr() attribute.KeyValue { return o.v.KeyValue() @@ -52,17 +52,17 @@ func (o taskDispatchSpanTaskID) taskDispatchStartAttr() attribute.KeyValue { // WithTaskDispatchTaskID sets `myapp.task.id` when StartTaskDispatch starts // the span. Samplers read it, so it is accepted only at start. -func WithTaskDispatchTaskID(v myappattr.TaskIDAttr) TaskDispatchStartAttr { +func WithTaskDispatchTaskID(v myappattr.TaskID) TaskDispatchStartAttr { return taskDispatchSpanTaskID{v: v} } -// TaskDispatchSpan is a started span of `worker.task.dispatch`. The zero -// TaskDispatchSpan records nothing. -type TaskDispatchSpan struct{ span trace.Span } +// TaskDispatch is a started span of `worker.task.dispatch`. The zero +// TaskDispatch records nothing. +type TaskDispatch struct{ span trace.Span } // Span returns the underlying trace.Span, or a no-op one for the zero -// TaskDispatchSpan. -func (s TaskDispatchSpan) Span() trace.Span { +// TaskDispatch. +func (s TaskDispatch) Span() trace.Span { if s.span == nil { return noop.Span{} } @@ -70,12 +70,12 @@ func (s TaskDispatchSpan) Span() trace.Span { } // End ends the span. -func (s TaskDispatchSpan) End(opts ...trace.SpanEndOption) { +func (s TaskDispatch) End(opts ...trace.SpanEndOption) { s.Span().End(opts...) } // SetAttributes sets attributes on the span after it started. -func (s TaskDispatchSpan) SetAttributes(attrs ...TaskDispatchAttr) { +func (s TaskDispatch) SetAttributes(attrs ...TaskDispatchAttr) { kvs := make([]attribute.KeyValue, 0, len(attrs)) for _, attr := range attrs { kvs = append(kvs, attr.taskDispatchStartAttr()) @@ -84,12 +84,12 @@ func (s TaskDispatchSpan) SetAttributes(attrs ...TaskDispatchAttr) { } // RecordError records err as an exception event on the span. -func (s TaskDispatchSpan) RecordError(err error, opts ...trace.EventOption) { +func (s TaskDispatch) RecordError(err error, opts ...trace.EventOption) { s.Span().RecordError(err, opts...) } // SetStatus sets the status of the span. -func (s TaskDispatchSpan) SetStatus(code codes.Code, description string) { +func (s TaskDispatch) SetStatus(code codes.Code, description string) { s.Span().SetStatus(code, description) } @@ -102,7 +102,7 @@ func (s TaskDispatchSpan) SetStatus(code codes.Code, description string) { // // The span is named `dispatch {worker.host.name}:{worker.host.port}`, with // each placeholder replaced by the value of the attribute it names. -func StartTaskDispatch(ctx context.Context, tracer semconvtracer.Tracer, myappTaskAttempt myappattr.TaskAttemptAttr, workerHostName workerattr.HostNameAttr, workerHostPort workerattr.HostPortAttr, opts ...TaskDispatchStartAttr) (context.Context, TaskDispatchSpan) { +func StartTaskDispatch(ctx context.Context, tracer semconvtracer.Tracer, myappTaskAttempt myappattr.TaskAttempt, workerHostName workerattr.HostName, workerHostPort workerattr.HostPort, opts ...TaskDispatchStartAttr) (context.Context, TaskDispatch) { kvs := make([]attribute.KeyValue, 0, 3+len(opts)) kvs = append(kvs, myappTaskAttempt.KeyValue()) kvs = append(kvs, workerHostName.KeyValue()) @@ -117,5 +117,5 @@ func StartTaskDispatch(ctx context.Context, tracer semconvtracer.Tracer, myappTa trace.WithSpanKind(trace.SpanKindClient), trace.WithAttributes(kvs...), ) - return ctx, TaskDispatchSpan{span: span} + return ctx, TaskDispatch{span: span} } diff --git a/templates/code/go/weaver.yaml b/templates/code/go/weaver.yaml index af74920..4d63118 100644 --- a/templates/code/go/weaver.yaml +++ b/templates/code/go/weaver.yaml @@ -338,9 +338,15 @@ templates: | group_by(.namespace) | map({namespace: .[0].namespace, attributes: sort_by(.key)}) | map( - (.attributes - | group_by(.short_name | gsub("[._]"; "") | ascii_downcase) - | map(select(length > 1) | map(.key) | join(" and "))) as $collisions + ([.attributes[] | . as $attr | (.short_name | gsub("[._]"; "") | ascii_downcase) as $short + | (["P:" + $short, "p:" + $short + "key"] + + (if (.type | type) == "object" + then [.type.members[] | "P:" + $short + (.id | gsub("[._]"; "") | ascii_downcase)] + else ["P:new" + $short] end))[] + | {identifier: ., name: $attr.key}] + | group_by(.identifier) + | map(select(length > 1) | map(.name) | unique | join(" and ")) + | unique) as $collisions | if ($collisions | length) > 0 then error("package \(.namespace)attr has attributes that render to the same Go identifier: \($collisions | join("; "))") else . end @@ -487,9 +493,11 @@ templates: ) | group_by(.namespace) | map( - ([.[] | .name as $metric | (.short_name | gsub("[._]"; "") | ascii_downcase) as $short | .instrument as $kind - | ([$short + $kind, $short + $kind + "attr", $short + $kind + "observer", $short + $kind + "callback"] - + (if $kind == "histogram" then [] else [$short + "observable" + $kind] end))[] + ([.[] | . as $def | .name as $metric | (.short_name | gsub("[._]"; "") | ascii_downcase) as $short + | (["P:" + $short, "P:new" + $short] + + (if ($def.optional | length) > 0 then ["P:" + $short + "attr"] else [] end) + + (if $def.instrument == "histogram" then [] else ["P:" + $short + "observer", "P:" + $short + "callback", "P:" + $short + "observable", "P:new" + $short + "observable"] end) + + ($def.optional | map(.attr_short_name | gsub("[._]"; "") | ascii_downcase) | map("P:with" + $short + ., "p:" + $short + .)))[] | {identifier: ., name: $metric}] | group_by(.identifier) | map(select(length > 1) | map(.name) | unique | join(" and ")) @@ -630,7 +638,7 @@ templates: | group_by(.namespace) | map( ([.[] | . as $def | .id as $span | (.short_name | norm) as $short - | (["P:start" + $short, "P:" + $short + "span"] + | (["P:start" + $short, "P:" + (if $short == "" then "span" else $short end)] + (if $def.name_parts then [] else ["P:" + $short + "name", "P:new" + $short + "name"] end) + (if ($def.optional | length) > 0 then ["P:" + $short + "startattr"] else [] end) + (if $def.has_late_attrs then ["P:" + $short + "attr"] else [] end) @@ -891,9 +899,10 @@ templates: | group_by(.namespace) | map( ([.[] | . as $def | .id as $entity | (.short_name | norm) as $short - | (["P:new" + $short + "entity", "P:" + $short + "entity"] - + (if ($def.optional | length) > 0 then ["P:" + $short + "entityattr"] else [] end) - + ($def.optional | map(.attr_short_name | norm) | map("P:with" + $short + "entity" + ., "p:" + $short + "entity" + .)))[] + | (if $short == "" then "entity" else $short end) as $type + | (["P:new" + $type, "P:" + $type] + + (if ($def.optional | length) > 0 then ["P:" + $type + "attr"] else [] end) + + ($def.optional | map(.attr_short_name | norm) | map("P:with" + $type + ., "p:" + $short + "entity" + .)))[] | {identifier: ., name: $entity}] | group_by(.identifier) | map(select(length > 1) | map(.name) | unique | join(" and ")) From 0ca185ef11f729b692bc16a86ca89bd0fc69fd88 Mon Sep 17 00:00:00 2001 From: Yordis Prieto Date: Tue, 13 Oct 2026 14:36:44 -0400 Subject: [PATCH 2/2] docs(go): pass the span name in the single-segment span example Signed-off-by: Yordis Prieto --- templates/code/go/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/code/go/README.md b/templates/code/go/README.md index aba168b..a439f08 100644 --- a/templates/code/go/README.md +++ b/templates/code/go/README.md @@ -332,7 +332,7 @@ has nothing left after its namespace. Rather than failing, it renders unprefixed, in its own `span` package: ```go -ctx, span := heartbeatspan.Start(ctx, tracer, heartbeatattr.NewSequence(1)) +ctx, span := heartbeatspan.Start(ctx, tracer, heartbeatspan.Name{}, heartbeatattr.NewSequence(1)) defer span.End() ```