@@ -33,7 +33,8 @@ import (
33
33
"github.com/elastic/opentelemetry-lib/enrichments/trace/config"
34
34
"go.opentelemetry.io/collector/pdata/pcommon"
35
35
"go.opentelemetry.io/collector/pdata/ptrace"
36
- semconv "go.opentelemetry.io/collector/semconv/v1.25.0"
36
+ semconv25 "go.opentelemetry.io/collector/semconv/v1.25.0"
37
+ semconv27 "go.opentelemetry.io/collector/semconv/v1.27.0"
37
38
tracepb "go.opentelemetry.io/proto/otlp/trace/v1"
38
39
"google.golang.org/grpc/codes"
39
40
)
@@ -68,6 +69,7 @@ type spanEnrichmentContext struct {
68
69
dbSystem string
69
70
messagingSystem string
70
71
messagingDestinationName string
72
+ genAiSystem string
71
73
72
74
serverPort int64
73
75
urlPort int64
@@ -82,6 +84,7 @@ type spanEnrichmentContext struct {
82
84
isHTTP bool
83
85
isDB bool
84
86
messagingDestinationTemp bool
87
+ isGenAi bool
85
88
}
86
89
87
90
func (s * spanEnrichmentContext ) Enrich (span ptrace.Span , cfg config.Config ) {
@@ -91,86 +94,89 @@ func (s *spanEnrichmentContext) Enrich(span ptrace.Span, cfg config.Config) {
91
94
// Extract information from span attributes.
92
95
span .Attributes ().Range (func (k string , v pcommon.Value ) bool {
93
96
switch k {
94
- case semconv .AttributePeerService :
97
+ case semconv25 .AttributePeerService :
95
98
s .peerService = v .Str ()
96
- case semconv .AttributeServerAddress :
99
+ case semconv25 .AttributeServerAddress :
97
100
s .serverAddress = v .Str ()
98
- case semconv .AttributeServerPort :
101
+ case semconv25 .AttributeServerPort :
99
102
s .serverPort = v .Int ()
100
- case semconv .AttributeNetPeerName :
103
+ case semconv25 .AttributeNetPeerName :
101
104
if s .serverAddress == "" {
102
105
// net.peer.name is deprecated, so has lower priority
103
106
// only set when not already set with server.address
104
107
// and allowed to be overridden by server.address.
105
108
s .serverAddress = v .Str ()
106
109
}
107
- case semconv .AttributeNetPeerPort :
110
+ case semconv25 .AttributeNetPeerPort :
108
111
if s .serverPort == 0 {
109
112
// net.peer.port is deprecated, so has lower priority
110
113
// only set when not already set with server.port and
111
114
// allowed to be overridden by server.port.
112
115
s .serverPort = v .Int ()
113
116
}
114
- case semconv .AttributeMessagingDestinationName :
117
+ case semconv25 .AttributeMessagingDestinationName :
115
118
s .isMessaging = true
116
119
s .messagingDestinationName = v .Str ()
117
- case semconv .AttributeMessagingOperation :
120
+ case semconv25 .AttributeMessagingOperation :
118
121
s .isMessaging = true
119
- case semconv .AttributeMessagingSystem :
122
+ case semconv25 .AttributeMessagingSystem :
120
123
s .isMessaging = true
121
124
s .messagingSystem = v .Str ()
122
- case semconv .AttributeMessagingDestinationTemporary :
125
+ case semconv25 .AttributeMessagingDestinationTemporary :
123
126
s .isMessaging = true
124
127
s .messagingDestinationTemp = true
125
- case semconv .AttributeHTTPStatusCode ,
126
- semconv .AttributeHTTPResponseStatusCode :
128
+ case semconv25 .AttributeHTTPStatusCode ,
129
+ semconv25 .AttributeHTTPResponseStatusCode :
127
130
s .isHTTP = true
128
131
s .httpStatusCode = v .Int ()
129
- case semconv .AttributeHTTPMethod ,
130
- semconv .AttributeHTTPRequestMethod ,
131
- semconv .AttributeHTTPTarget ,
132
- semconv .AttributeHTTPScheme ,
133
- semconv .AttributeHTTPFlavor ,
134
- semconv .AttributeNetHostName :
132
+ case semconv25 .AttributeHTTPMethod ,
133
+ semconv25 .AttributeHTTPRequestMethod ,
134
+ semconv25 .AttributeHTTPTarget ,
135
+ semconv25 .AttributeHTTPScheme ,
136
+ semconv25 .AttributeHTTPFlavor ,
137
+ semconv25 .AttributeNetHostName :
135
138
s .isHTTP = true
136
- case semconv .AttributeURLFull ,
137
- semconv .AttributeHTTPURL :
139
+ case semconv25 .AttributeURLFull ,
140
+ semconv25 .AttributeHTTPURL :
138
141
s .isHTTP = true
139
142
// ignoring error as if parse fails then we don't want the url anyway
140
143
s .urlFull , _ = url .Parse (v .Str ())
141
- case semconv .AttributeURLScheme :
144
+ case semconv25 .AttributeURLScheme :
142
145
s .isHTTP = true
143
146
s .urlScheme = v .Str ()
144
- case semconv .AttributeURLDomain :
147
+ case semconv25 .AttributeURLDomain :
145
148
s .isHTTP = true
146
149
s .urlDomain = v .Str ()
147
- case semconv .AttributeURLPort :
150
+ case semconv25 .AttributeURLPort :
148
151
s .isHTTP = true
149
152
s .urlPort = v .Int ()
150
- case semconv .AttributeURLPath :
153
+ case semconv25 .AttributeURLPath :
151
154
s .isHTTP = true
152
155
s .urlPath = v .Str ()
153
- case semconv .AttributeURLQuery :
156
+ case semconv25 .AttributeURLQuery :
154
157
s .isHTTP = true
155
158
s .urlQuery = v .Str ()
156
- case semconv .AttributeRPCGRPCStatusCode :
159
+ case semconv25 .AttributeRPCGRPCStatusCode :
157
160
s .isRPC = true
158
161
s .grpcStatus = codes .Code (v .Int ()).String ()
159
- case semconv .AttributeRPCSystem :
162
+ case semconv25 .AttributeRPCSystem :
160
163
s .isRPC = true
161
164
s .rpcSystem = v .Str ()
162
- case semconv .AttributeRPCService :
165
+ case semconv25 .AttributeRPCService :
163
166
s .isRPC = true
164
167
s .rpcService = v .Str ()
165
- case semconv .AttributeDBStatement ,
166
- semconv .AttributeDBUser :
168
+ case semconv25 .AttributeDBStatement ,
169
+ semconv25 .AttributeDBUser :
167
170
s .isDB = true
168
- case semconv .AttributeDBName :
171
+ case semconv25 .AttributeDBName :
169
172
s .isDB = true
170
173
s .dbName = v .Str ()
171
- case semconv .AttributeDBSystem :
174
+ case semconv25 .AttributeDBSystem :
172
175
s .isDB = true
173
176
s .dbSystem = v .Str ()
177
+ case semconv27 .AttributeGenAiSystem :
178
+ s .isGenAi = true
179
+ s .genAiSystem = v .Str ()
174
180
}
175
181
return true
176
182
})
@@ -361,6 +367,9 @@ func (s *spanEnrichmentContext) setSpanTypeSubtype(span ptrace.Span) {
361
367
case s .isHTTP :
362
368
spanType = "external"
363
369
spanSubtype = "http"
370
+ case s .isGenAi :
371
+ spanType = "genai"
372
+ spanSubtype = s .genAiSystem
364
373
default :
365
374
switch span .Kind () {
366
375
case ptrace .SpanKindInternal :
@@ -504,11 +513,11 @@ func (s *spanEventEnrichmentContext) enrich(
504
513
if s .exception {
505
514
se .Attributes ().Range (func (k string , v pcommon.Value ) bool {
506
515
switch k {
507
- case semconv .AttributeExceptionEscaped :
516
+ case semconv25 .AttributeExceptionEscaped :
508
517
s .exceptionEscaped = v .Bool ()
509
- case semconv .AttributeExceptionType :
518
+ case semconv25 .AttributeExceptionType :
510
519
s .exceptionType = v .Str ()
511
- case semconv .AttributeExceptionMessage :
520
+ case semconv25 .AttributeExceptionMessage :
512
521
s .exceptionMessage = v .Str ()
513
522
}
514
523
return true
0 commit comments