Skip to content

Provide ability to define span.kind for OpenTelemetry Layer #945

Closed
@alessandrobologna

Description

@alessandrobologna

Hi,
I wanted to propose a small enhancement to the OpenTelemetry tracing layer implementation in the AWS Lambda Rust runtime.

Currently, in otel.rs, the tracing span for Lambda invocations doesn't include a way to specify the span kind (e.g., server, client). Adding this capability could improve how systems are represented in observability platforms.

My suggestion: we could add an otel.kind field to the span creation, initialized as empty. This would allow users to set the span kind in their handlers if needed. For example:

let span = tracing::info_span!(
    "Lambda function invocation",
    "otel.name" = req.context.env_config.function_name,
    "otel.kind" = field::Empty,  // New field for span kind
    { traceconv::FAAS_TRIGGER } = &self.otel_attribute_trigger,
    { traceconv::FAAS_INVOCATION_ID } = req.context.request_id,
    { traceconv::FAAS_COLDSTART } = self.coldstart
);

Users could then set the span kind in their handler like this:

use tracing::Span;

async fn handler(event: Value, _: Context) -> Result<Value, Error> {
    let span = Span::current();
    span.record("otel.kind", "server");
    
    // Handler logic...
}

This change should be backward compatible and provide more flexibility for users. I'd love to hear your thoughts on this, and happy to propose a PR!

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