Skip to content

Commit fbed4f3

Browse files
committed
Emit repo nickname as process span attribute
If we have a repo nickname value present in the trace2.param.set, then emit this as a process span attribute directly "trace2.repo.nickname". This will make it easier to make decisions on routing of these traces in the collector, without having to resort to parsing the trace2.param.set JSON object. Signed-off-by: Matthew John Cheetham <[email protected]>
1 parent 2b3f1b8 commit fbed4f3

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

trace2dataset.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ func (tr2 *trace2Dataset) exportTraces() {
510510
return
511511
}
512512

513-
traces := tr2.ToTraces(dl)
513+
traces := tr2.ToTraces(dl, tr2.rcvr_base.RcvrConfig.filterSettings.Keynames)
514514

515515
err := tr2.rcvr_base.TracesConsumer.ConsumeTraces(tr2.rcvr_base.ctx, traces)
516516
if err != nil {

trace2emitotlp.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func (tr2 *trace2Dataset) insertResourceInstrumentationScope(instScope pcommon.I
8989
instScope.SetVersion(Trace2ReceiverVersion)
9090
}
9191

92-
func (tr2 *trace2Dataset) ToTraces(dl FilterDetailLevel) ptrace.Traces {
92+
func (tr2 *trace2Dataset) ToTraces(dl FilterDetailLevel, keynames FilterKeynames) ptrace.Traces {
9393
pt := ptrace.NewTraces()
9494

9595
resourceSpans := pt.ResourceSpans().AppendEmpty()
@@ -108,7 +108,7 @@ func (tr2 *trace2Dataset) ToTraces(dl FilterDetailLevel) ptrace.Traces {
108108

109109
// Create an OTEL span for the entire process (aka the main thread).
110110
exeSpan := scopes.Spans().AppendEmpty()
111-
emitProcessSpan(&exeSpan, tr2, dl)
111+
emitProcessSpan(&exeSpan, tr2, dl, keynames)
112112

113113
if WantRegionAndThreadSpans(dl) {
114114
// Create an OTEL span for the lifetime of each non-main thread.
@@ -188,7 +188,7 @@ func emitSpanEssentials(span *ptrace.Span, r *TrSpanEssentials, tr2 *trace2Datas
188188
span.SetTraceID(tr2.otelTraceID)
189189
}
190190

191-
func emitProcessSpan(span *ptrace.Span, tr2 *trace2Dataset, dl FilterDetailLevel) {
191+
func emitProcessSpan(span *ptrace.Span, tr2 *trace2Dataset, dl FilterDetailLevel, keynames FilterKeynames) {
192192
emitSpanEssentials(span, &tr2.process.mainThread.lifetime, tr2)
193193
span.SetKind(ptrace.SpanKindServer)
194194

@@ -254,6 +254,16 @@ func emitProcessSpan(span *ptrace.Span, tr2 *trace2Dataset, dl FilterDetailLevel
254254
sm.PutStr(string(Trace2ParamSet), string(jargs))
255255
}
256256

257+
// Emit the repo nickname value directly if present. This is done to make
258+
// it easier to query on them in the collector pipeline without having to
259+
// parse JSON blobs.
260+
if len(keynames.NicknameKey) > 0 {
261+
nnvalue, ok := tr2.process.paramSetValues[keynames.NicknameKey]
262+
if ok && len(nnvalue) > 0 {
263+
sm.PutStr(string(Trace2RepoNickname), nnvalue)
264+
}
265+
}
266+
257267
if WantMainThreadTimersAndCounters(dl) {
258268
// Emit per-thread counters and timers for the main thread because
259269
// it is not handled by `emitNonMainThreadSpan()`.

trace2semconv.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ const (
9999
Trace2RepoSet = attribute.Key("trace2.repo.set")
100100
Trace2ParamSet = attribute.Key("trace2.param.set")
101101

102+
Trace2RepoNickname = attribute.Key("trace2.repo.nickname")
103+
102104
Trace2ProcessData = attribute.Key("trace2.process.data")
103105
Trace2ProcessTimers = attribute.Key("trace2.process.timers")
104106
Trace2ProcessCounters = attribute.Key("trace2.process.counters")

0 commit comments

Comments
 (0)