Skip to content

Commit 0d66756

Browse files
authored
Merge branch 'main' into codeboten/bump-otel-go
2 parents 9091a91 + 58e643b commit 0d66756

File tree

25 files changed

+362
-76
lines changed

25 files changed

+362
-76
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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: breaking
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
7+
component: mdatagen
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Add context parameter for recording event to set traceID and spanID
11+
12+
# One or more tracking issues or pull requests related to the change
13+
issues: [12571]
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+
20+
# Optional: The change log or logs in which this entry should be included.
21+
# e.g. '[user]' or '[user, api]'
22+
# Include 'user' if the change is relevant to end users.
23+
# Include 'api' if there is a change to a library API.
24+
# Default: '[user]'
25+
change_logs: [api]
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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: deprecation
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
7+
component: pdata/profile
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Replace AddAttribute with the PutAttribute helper method to modify the content of attributable records.
11+
12+
# One or more tracking issues or pull requests related to the change
13+
issues: [12798]
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+
20+
# Optional: The change log or logs in which this entry should be included.
21+
# e.g. '[user]' or '[user, api]'
22+
# Include 'user' if the change is relevant to end users.
23+
# Include 'api' if there is a change to a library API.
24+
# Default: '[user]'
25+
change_logs: [api]

cmd/mdatagen/internal/samplereceiver/internal/metadata/generated_logs.go

Lines changed: 30 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/mdatagen/internal/samplereceiver/internal/metadata/generated_logs_test.go

Lines changed: 18 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/mdatagen/internal/templates/logs.go.tmpl

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ import (
1212
{{- if .SemConvVersion }}
1313
conventions "go.opentelemetry.io/otel/semconv/v{{ .SemConvVersion }}"
1414
{{- end }}
15+
{{- if .Events }}
16+
"context"
17+
"go.opentelemetry.io/otel/trace"
18+
"go.opentelemetry.io/collector/filter"
19+
{{- end }}
1520
)
1621

1722

@@ -21,15 +26,21 @@ type event{{ $name.Render }} struct {
2126
config EventConfig // event config provided by user.
2227
}
2328

24-
func (e *event{{ $name.Render }}) recordEvent(timestamp pcommon.Timestamp
29+
func (e *event{{ $name.Render }}) recordEvent(ctx context.Context, timestamp pcommon.Timestamp
2530
{{- range $event.Attributes -}}, {{ .RenderUnexported }}AttributeValue {{ (attributeInfo .).Type.Primitive }}{{ end }}) {
2631
if !e.config.Enabled {
2732
return
2833
}
2934
lr := e.data.AppendEmpty()
3035
lr.SetEventName("{{ $name }}")
3136
lr.SetTimestamp(timestamp)
32-
{{- range $event.Attributes }}
37+
38+
if span := trace.SpanContextFromContext(ctx); span.IsValid() {
39+
lr.SetTraceID(pcommon.TraceID(span.TraceID()))
40+
lr.SetSpanID(pcommon.SpanID(span.SpanID()))
41+
}
42+
43+
{{ range $event.Attributes }}
3344
{{- if eq (attributeInfo .).Type.Primitive "[]byte" }}
3445
lr.Attributes().PutEmptyBytes("{{ (attributeInfo .).Name }}").FromRaw({{ .RenderUnexported }}AttributeValue)
3546
{{- else if eq (attributeInfo .).Type.Primitive "[]any" }}
@@ -236,11 +247,11 @@ func (lb *LogsBuilder) Emit(options ...ResourceLogsOption) plog.Logs {
236247

237248
{{ range $name, $event := .Events -}}
238249
// Record{{ $name.Render }}Event adds a log record of {{ $name }} event.
239-
func (lb *LogsBuilder) Record{{ $name.Render }}Event(timestamp pcommon.Timestamp
250+
func (lb *LogsBuilder) Record{{ $name.Render }}Event(ctx context.Context, timestamp pcommon.Timestamp
240251
{{- range $event.Attributes -}}
241252
, {{ .RenderUnexported }}AttributeValue {{ if (attributeInfo .).Enum }}Attribute{{ .Render }}{{ else }}{{ (attributeInfo .).Type.Primitive }}{{ end }}
242253
{{- end }}) {
243-
lb.event{{ $name.Render }}.recordEvent(timestamp
254+
lb.event{{ $name.Render }}.recordEvent(ctx, timestamp
244255
{{- range $event.Attributes -}}
245256
, {{ .RenderUnexported }}AttributeValue{{ if (attributeInfo .).Enum }}.String(){{ end }}
246257
{{- end }})

cmd/mdatagen/internal/templates/logs_test.go.tmpl

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,18 @@ package {{ .Package }}
55
import (
66
"time"
77
"testing"
8-
98
"github.com/stretchr/testify/assert"
109
"go.uber.org/zap"
1110
"go.uber.org/zap/zaptest/observer"
12-
13-
"go.opentelemetry.io/collector/pdata/pcommon"
14-
"go.opentelemetry.io/collector/pdata/plog"
15-
{{- if or isReceiver isScraper }}
16-
"go.opentelemetry.io/collector/{{ .Status.Class }}/{{ .Status.Class }}test"
17-
{{- end }}
11+
"go.opentelemetry.io/collector/pdata/pcommon"
12+
"go.opentelemetry.io/collector/pdata/plog"
13+
{{- if or isReceiver isScraper }}
14+
"go.opentelemetry.io/collector/{{ .Status.Class }}/{{ .Status.Class }}test"
15+
{{- end }}
16+
{{- if .Events }}
17+
"context"
18+
"go.opentelemetry.io/otel/trace"
19+
{{- end }}
1820
)
1921

2022
{{- if .Events }}
@@ -128,6 +130,13 @@ func TestLogsBuilder(t *testing.T) {
128130
for _, tt := range tests {
129131
t.Run(tt.name, func(t *testing.T) {
130132
timestamp := pcommon.Timestamp(1_000_001_000)
133+
traceID := [16]byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}
134+
spanID := [8]byte{0, 1, 2, 3, 4, 5, 6, 7}
135+
ctx := trace.ContextWithSpanContext(context.Background(), trace.NewSpanContext(trace.SpanContextConfig{
136+
TraceID: trace.TraceID(traceID),
137+
SpanID: trace.SpanID(spanID),
138+
TraceFlags: trace.FlagsSampled,
139+
}))
131140
observedZapCore, observedLogs := observer.New(zap.WarnLevel)
132141
{{- if or isReceiver isScraper }}
133142
settings := {{ .Status.Class }}test.NewNopSettings({{ .Status.Class }}test.NopType)
@@ -185,7 +194,7 @@ func TestLogsBuilder(t *testing.T) {
185194
{{- range $name, $event := .Events }}
186195
{{ if $event.Enabled }}defaultEventsCount++{{ end }}
187196
allEventsCount++
188-
lb.Record{{ $name.Render }}Event(timestamp
197+
lb.Record{{ $name.Render }}Event(ctx, timestamp
189198
{{- range $event.Attributes -}}
190199
, {{ if (attributeInfo .).Enum }}Attribute{{ .Render }}{{ (index (attributeInfo .).Enum 0) | publicVar }}{{ else }}{{ (attributeInfo .).TestValue }}{{ end }}
191200
{{- end }})
@@ -231,6 +240,8 @@ func TestLogsBuilder(t *testing.T) {
231240
validatedEvents["{{ $name }}"] = true
232241
lr := lrs.At(i)
233242
assert.Equal(t, timestamp, lr.Timestamp())
243+
assert.Equal(t, pcommon.TraceID(traceID), lr.TraceID())
244+
assert.Equal(t, pcommon.SpanID(spanID), lr.SpanID())
234245

235246
{{- range $i, $attr := $event.Attributes }}
236247
attrVal, ok {{ if eq $i 0 }}:{{ end }}= lr.Attributes().Get("{{ (attributeInfo $attr).Name }}")

cmd/mdatagen/metadata-schema.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,28 @@ metrics:
117117
# Optional: array of attributes that were defined in the attributes section that are emitted by this metric.
118118
attributes: [string]
119119

120+
# Optional: map of event names with the key being the event name and value
121+
# being described below.
122+
events:
123+
<event.name>:
124+
# Required: whether the event is collected by default.
125+
enabled: bool
126+
# Required: event description.
127+
description:
128+
# Optional: extended documentation of the event.
129+
extended_documentation:
130+
# Optional: warnings that will be shown to user under specified conditions.
131+
warnings:
132+
# A warning that will be displayed if the event is enabled in user config.
133+
# Should be used for deprecated default events that will be removed soon.
134+
if_enabled:
135+
# A warning that will be displayed if `enabled` field is not set explicitly in user config.
136+
if_enabled_not_set:
137+
# A warning that will be displayed if the event is configured by user in any way.
138+
if_configured:
139+
# Optional: array of attributes that were defined in the attributes section that are emitted by this event.
140+
attributes: [string]
141+
120142
# Lifecycle tests generated for this component.
121143
tests:
122144
config: # {} by default, specific testing configuration for lifecycle tests.

cmd/otelcorecol/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ require (
3939
github.com/cenkalti/backoff/v5 v5.0.2 // indirect
4040
github.com/cespare/xxhash/v2 v2.3.0 // indirect
4141
github.com/davecgh/go-spew v1.1.1 // indirect
42-
github.com/ebitengine/purego v0.8.4-0.20250520125605-a52bc8357ac9 // indirect
42+
github.com/ebitengine/purego v0.8.4 // indirect
4343
github.com/felixge/httpsnoop v1.0.4 // indirect
4444
github.com/foxboron/go-tpm-keyfiles v0.0.0-20250323135004-b31fac66206e // indirect
4545
github.com/fsnotify/fsnotify v1.9.0 // indirect

cmd/otelcorecol/go.sum

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

extension/memorylimiterextension/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ require (
1616

1717
require (
1818
github.com/davecgh/go-spew v1.1.1 // indirect
19-
github.com/ebitengine/purego v0.8.4-0.20250520125605-a52bc8357ac9 // indirect
19+
github.com/ebitengine/purego v0.8.4 // indirect
2020
github.com/go-logr/logr v1.4.2 // indirect
2121
github.com/go-logr/stdr v1.2.2 // indirect
2222
github.com/go-ole/go-ole v1.2.6 // indirect

0 commit comments

Comments
 (0)