Skip to content

unknown type for gen_ai spans #111

@xrmx

Description

@xrmx

When tracing a python langchain application with opentelemetry-instrumentation-langchain (provided by openllmetry) we may produce spans like this:

{
    "name": "AzureChatOpenAI.chat",
    "context": {
        "trace_id": "0xdf0874b5202669e839de54311930359c",
        "span_id": "0x731e8d3b3a82268f",
        "trace_state": "[]"
    },
    "kind": "SpanKind.CLIENT",
    "parent_id": "0xdf313e3a840d43d3",
    "start_time": "2024-10-15T08:04:04.522445Z",
    "end_time": "2024-10-15T08:04:06.125744Z",
    "status": {
        "status_code": "UNSET"
    },
    "attributes": {
        "traceloop.workflow.name": "ConversationalRetrievalChain",
        "traceloop.entity.path": "StuffDocumentsChain.LLMChain",
        "gen_ai.system": "Langchain",
        "llm.request.type": "chat",
        "gen_ai.request.model": "gpt-4o-mini",
        "gen_ai.response.model": "gpt-4o-mini",
        "gen_ai.request.temperature": 0.7,
        "gen_ai.prompt.0.role": "user",
        "gen_ai.prompt.0.content": "somecontent",
        "gen_ai.completion.0.role": "assistant"
    },
    "events": [],
    "links": [],
    "resource": {
        "attributes": {
            "telemetry.sdk.language": "python",
            "telemetry.sdk.name": "opentelemetry",
            "telemetry.sdk.version": "1.27.0",
            "service.name": "foobar",
            "service.version": "1.0",
            "deployment.environment": "production",
            "service.instance.id": "gcpvmlls01",
            "telemetry.auto.version": "0.48b0"
        },
        "schema_url": ""
    }
}

that ends up having an unknown span type in kibana which does not look great.

Image

Please note that this span is not following the OTel genai convention but if we want to add a special type for genai stuff the presence of the gen_ai.system attribute is in the semconv while this particular value (langchain) is not.

Here's the current enrichment code setting the span.type:

func (s *spanEnrichmentContext) setSpanTypeSubtype(span ptrace.Span) {
var spanType, spanSubtype string
switch {
case s.isDB:
spanType = "db"
spanSubtype = s.dbSystem
case s.isMessaging:
spanType = "messaging"
spanSubtype = s.messagingSystem
case s.isRPC:
spanType = "external"
spanSubtype = s.rpcSystem
case s.isHTTP:
spanType = "external"
spanSubtype = "http"
default:
switch span.Kind() {
case ptrace.SpanKindInternal:
spanType = "app"
spanSubtype = "internal"
default:
spanType = "unknown"
}
}
span.Attributes().PutStr(AttributeSpanType, spanType)
if spanSubtype != "" {
span.Attributes().PutStr(AttributeSpanSubtype, spanSubtype)
}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions