Skip to content

Commit

Permalink
Feature/otel span kind support (#946)
Browse files Browse the repository at this point in the history
* feat(otel): add span kind support to Lambda invocation tracing

* fix fmt

* docs(example): demonstrate OpenTelemetry span kind usage

* fix fmt
  • Loading branch information
alessandrobologna authored Dec 12, 2024
1 parent f024fd0 commit 9416d72
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
3 changes: 3 additions & 0 deletions examples/opentelemetry-tracing/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use lambda_runtime::{
layers::{OpenTelemetryFaasTrigger, OpenTelemetryLayer as OtelLayer},
tracing::Span,
LambdaEvent, Runtime,
};
use opentelemetry::trace::TracerProvider;
Expand All @@ -8,6 +9,8 @@ use tower::{service_fn, BoxError};
use tracing_subscriber::prelude::*;

async fn echo(event: LambdaEvent<serde_json::Value>) -> Result<serde_json::Value, &'static str> {
let span = Span::current();
span.record("otel.kind", "SERVER");
Ok(event.payload)
}

Expand Down
3 changes: 2 additions & 1 deletion lambda-runtime/src/layers/otel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::LambdaInvocation;
use opentelemetry_semantic_conventions::trace as traceconv;
use pin_project::pin_project;
use tower::{Layer, Service};
use tracing::{instrument::Instrumented, Instrument};
use tracing::{field, instrument::Instrumented, Instrument};

/// Tower layer to add OpenTelemetry tracing to a Lambda function invocation. The layer accepts
/// a function to flush OpenTelemetry after the end of the invocation.
Expand Down Expand Up @@ -75,6 +75,7 @@ where
let span = tracing::info_span!(
"Lambda function invocation",
"otel.name" = req.context.env_config.function_name,
"otel.kind" = field::Empty,
{ traceconv::FAAS_TRIGGER } = &self.otel_attribute_trigger,
{ traceconv::FAAS_INVOCATION_ID } = req.context.request_id,
{ traceconv::FAAS_COLDSTART } = self.coldstart
Expand Down

0 comments on commit 9416d72

Please sign in to comment.