Skip to content

Commit f847043

Browse files
[service] Enable scope information in default Prometheus exporter (open-telemetry#13344)
#### Description This changes the config for the default Prometheus exporter to remove `disable_scope_info: true`. This prevent errors in the exporter caused by metrics only differentiated by their scope being considered aliasing, which will become more common when the `telemetry.newPipelineTelemetry` feature gate graduates (see tracking issue for details). I marked this as a "breaking change", but I'm not sure if we make guarantees about the format of the Prometheus metrics we emit? #### Link to tracking issue Fixes open-telemetry#12939 #### Testing I updated some tests to reflect the additional labels added to Prometheus metrics. I performed manual testing and confirmed that the reproduction case in the tracking issue no longer emits an error when the feature gate is enabled.
1 parent c34566d commit f847043

File tree

5 files changed

+63
-18
lines changed

5 files changed

+63
-18
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: 'bug_fix'
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
7+
component: service
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Default internal metrics config now enables `otel_scope_` labels
11+
12+
# One or more tracking issues or pull requests related to the change
13+
issues: [12939, 13344]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext: |
19+
By default, the Collector exports its internal metrics using a Prometheus
20+
exporter from the opentelemetry-go repository. With this change, the Collector
21+
no longer sets "without_scope_info" to true in its configuration.
22+
23+
This means that all exported metrics will have `otel_scope_name`,
24+
`otel_scope_schema_url`, and `otel_scope_version` labels corresponding to the
25+
instrumentation scope metadata for that metric.
26+
27+
This notably prevents an error when multiple metrics are only distinguished
28+
by their instrumentation scopes and end up aliased during export.
29+
30+
If this is not desired behavior, a Prometheus exporter can be explicitly
31+
configured with this option enabled.
32+
33+
# Optional: The change log or logs in which this entry should be included.
34+
# e.g. '[user]' or '[user, api]'
35+
# Include 'user' if the change is relevant to end users.
36+
# Include 'api' if there is a change to a library API.
37+
# Default: '[user]'
38+
change_logs: []

service/config_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ func TestConfmapMarshalConfig(t *testing.T) {
113113
"with_resource_constant_labels": map[string]any{
114114
"included": []any{},
115115
},
116-
"without_scope_info": true,
117116
"without_type_suffix": true,
118117
"without_units": true,
119118
},

service/internal/promtest/server_util.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ func addrToPrometheus(address string) *config.Prometheus {
3636
return &config.Prometheus{
3737
Host: &host,
3838
Port: &portInt,
39-
WithoutScopeInfo: ptr(true),
4039
WithoutUnits: ptr(true),
4140
WithoutTypeSuffix: ptr(true),
4241
WithResourceConstantLabels: &config.IncludeExclude{

service/telemetry/factory.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ func createDefaultConfig() component.Config {
104104
Readers: []config.MetricReader{
105105
{
106106
Pull: &config.PullMetricReader{Exporter: config.PullMetricExporter{Prometheus: &config.Prometheus{
107-
WithoutScopeInfo: newPtr(true),
108107
WithoutUnits: newPtr(true),
109108
WithoutTypeSuffix: newPtr(true),
110109
Host: &metricsHost,

service/telemetry/metrics_test.go

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const (
2828
otelPrefix = "otel_sdk_"
2929
grpcPrefix = "grpc_"
3030
httpPrefix = "http_"
31+
scopeName = "collector_test"
3132
counterName = "test_counter"
3233
)
3334

@@ -49,30 +50,39 @@ func TestTelemetryInit(t *testing.T) {
4950
metricPrefix + otelPrefix + counterName: {
5051
value: 13,
5152
labels: map[string]string{
52-
"service_name": "otelcol",
53-
"service_version": "latest",
54-
"service_instance_id": testInstanceID,
53+
"service_name": "otelcol",
54+
"service_version": "latest",
55+
"service_instance_id": testInstanceID,
56+
"otel_scope_name": scopeName,
57+
"otel_scope_schema_url": "",
58+
"otel_scope_version": "",
5559
},
5660
},
5761
metricPrefix + grpcPrefix + counterName: {
5862
value: 11,
5963
labels: map[string]string{
60-
"net_sock_peer_addr": "",
61-
"net_sock_peer_name": "",
62-
"net_sock_peer_port": "",
63-
"service_name": "otelcol",
64-
"service_version": "latest",
65-
"service_instance_id": testInstanceID,
64+
"net_sock_peer_addr": "",
65+
"net_sock_peer_name": "",
66+
"net_sock_peer_port": "",
67+
"service_name": "otelcol",
68+
"service_version": "latest",
69+
"service_instance_id": testInstanceID,
70+
"otel_scope_name": "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc",
71+
"otel_scope_schema_url": "",
72+
"otel_scope_version": "",
6673
},
6774
},
6875
metricPrefix + httpPrefix + counterName: {
6976
value: 10,
7077
labels: map[string]string{
71-
"net_host_name": "",
72-
"net_host_port": "",
73-
"service_name": "otelcol",
74-
"service_version": "latest",
75-
"service_instance_id": testInstanceID,
78+
"net_host_name": "",
79+
"net_host_port": "",
80+
"service_name": "otelcol",
81+
"service_version": "latest",
82+
"service_instance_id": testInstanceID,
83+
"otel_scope_name": "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp",
84+
"otel_scope_schema_url": "",
85+
"otel_scope_version": "",
7686
},
7787
},
7888
"target_info": {
@@ -160,7 +170,7 @@ func TestTelemetryInit(t *testing.T) {
160170

161171
func createTestMetrics(t *testing.T, mp metric.MeterProvider) {
162172
// Creates a OTel Go counter
163-
counter, err := mp.Meter("collector_test").Int64Counter(metricPrefix+otelPrefix+counterName, metric.WithUnit("ms"))
173+
counter, err := mp.Meter(scopeName).Int64Counter(metricPrefix+otelPrefix+counterName, metric.WithUnit("ms"))
164174
require.NoError(t, err)
165175
counter.Add(context.Background(), 13)
166176

0 commit comments

Comments
 (0)