Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add specific type and subtype for otlp gen_ai spans #414

Merged
merged 2 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion input/otlp/traces.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ const (
attributeStackTrace = "code.stacktrace" // semconv 1.24 or later
attributeDataStreamDataset = "data_stream.dataset"
attributeDataStreamNamespace = "data_stream.namespace"
attributeGenAiSystem = "gen_ai.system"
)

// ConsumeTracesResult contains the number of rejected spans and error message for partial success response.
Expand Down Expand Up @@ -615,14 +616,18 @@ func TranslateSpan(spanKind ptrace.SpanKind, attributes pcommon.Map, event *mode
rpcService string
)

var (
genAiSystem string
)

var http modelpb.HTTP
var httpRequest modelpb.HTTPRequest
var httpResponse modelpb.HTTPResponse
var message modelpb.Message
var db modelpb.DB
var destinationService modelpb.DestinationService
var serviceTarget modelpb.ServiceTarget
var isHTTP, isDatabase, isRPC, isMessaging bool
var isHTTP, isDatabase, isRPC, isMessaging, isGenAi bool
var samplerType, samplerParam pcommon.Value
attributes.Range(func(kDots string, v pcommon.Value) bool {
if isJaeger {
Expand Down Expand Up @@ -812,6 +817,11 @@ func TranslateSpan(spanKind ptrace.SpanKind, attributes pcommon.Map, event *mode
// stacktrace is expected to be large thus un-truncated value is needed
event.Code.Stacktrace = v.Str()

// gen_ai.*
case attributeGenAiSystem:
genAiSystem = stringval
isGenAi = true

// miscellaneous
case "span.kind": // filter out
case semconv.AttributePeerService:
Expand Down Expand Up @@ -991,6 +1001,10 @@ func TranslateSpan(spanKind ptrace.SpanKind, attributes pcommon.Map, event *mode
destinationService.Resource = resource
}
}
case isGenAi:
event.Span.Type = "genai"
event.Span.Subtype = genAiSystem
serviceTarget.Type = event.Span.Type
default:
// Only set event.Span.Type if not already set
if event.Span.Type == "" {
Expand Down
10 changes: 10 additions & 0 deletions input/otlp/traces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1438,6 +1438,16 @@ func TestSpanEventsDataStream(t *testing.T) {
}
}

func TestGenAiSpan(t *testing.T) {
event := transformSpanWithAttributes(t, map[string]interface{}{
"gen_ai.system": "openai",
})

assert.Equal(t, "genai", event.Span.Type)
assert.Equal(t, "openai", event.Span.Subtype)
assert.Equal(t, "", event.Span.Action)
}

func transformTransactionWithAttributes(t *testing.T, attrs map[string]interface{}, configFns ...func(ptrace.Span)) *modelpb.APMEvent {
traces, spans := newTracesSpans()
otelSpan := spans.Spans().AppendEmpty()
Expand Down
Loading