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

unknown type for some langchain spans #111

Open
xrmx opened this issue Oct 15, 2024 · 0 comments
Open

unknown type for some langchain spans #111

xrmx opened this issue Oct 15, 2024 · 0 comments

Comments

@xrmx
Copy link
Member

xrmx commented Oct 15, 2024

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.

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)
}
}

@xrmx xrmx changed the title unknown type for langchain spans unknown type for some langchain spans Oct 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant