Skip to content

Commit

Permalink
Swap List[Attribute[_]] to Attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcardell committed Sep 16, 2024
1 parent 81ce08d commit 84d303b
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ object TracedHandlerSuite {

override def spanKind: SpanKind = SpanKind.Consumer

override def attributes(e: TestEvent): List[Attribute[_]] = List.empty
override def attributes(e: TestEvent): Attributes = Attributes.empty

}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import org.typelevel.otel4s.AttributeKey
/**
* Temporary aliases for Lambda message-specific attributes in otel4s-semconv-experimental
*/
object LambdaMessageAttributes {
private[otel4s] object LambdaMessageAttributes {
val MessagingSystem = AttributeKey.string("messaging.system")
object MessagingSystemValue {
object Sqs {
Expand All @@ -43,7 +43,7 @@ object LambdaMessageAttributes {
/**
* Temporary aliases for Lambda platform attributes in otel4s-semconv-experimental
*/
object LambdaContextAttributes {
private[otel4s] object LambdaContextAttributes {
val FaasInvocationId = AttributeKey.string("faas.invocation_id")
val FaasTrigger = AttributeKey.string("faas.trigger")
object FaasTriggerValue {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import feral.lambda.events.ApiGatewayProxyEventV2
import feral.lambda.events.DynamoDbStreamEvent
import feral.lambda.events.S3BatchEvent
import feral.lambda.events.SqsEvent
import org.typelevel.otel4s.Attribute
import org.typelevel.otel4s.Attributes
import org.typelevel.otel4s.trace.SpanKind

trait EventAttributeSources {
Expand All @@ -32,7 +32,7 @@ trait EventAttributeSources {

def spanKind: SpanKind = SpanKind.Consumer

def attributes(e: SqsEvent): List[Attribute[_]] =
def attributes(e: SqsEvent): Attributes =
SqsEventAttributes()
}

Expand All @@ -43,7 +43,7 @@ trait EventAttributeSources {

def spanKind: SpanKind = SpanKind.Consumer

def attributes(e: DynamoDbStreamEvent): List[Attribute[_]] =
def attributes(e: DynamoDbStreamEvent): Attributes =
DynamoDbStreamEventAttributes()
}

Expand All @@ -54,7 +54,7 @@ trait EventAttributeSources {

def spanKind: SpanKind = SpanKind.Server

def attributes(e: ApiGatewayProxyEvent): List[Attribute[_]] =
def attributes(e: ApiGatewayProxyEvent): Attributes =
ApiGatewayProxyEventAttributes()
}

Expand All @@ -65,7 +65,7 @@ trait EventAttributeSources {

def spanKind: SpanKind = SpanKind.Server

def attributes(e: ApiGatewayProxyEventV2): List[Attribute[_]] =
def attributes(e: ApiGatewayProxyEventV2): Attributes =
ApiGatewayProxyEventAttributes()
}

Expand All @@ -76,7 +76,7 @@ trait EventAttributeSources {

def spanKind: SpanKind = SpanKind.Server

def attributes(e: S3BatchEvent): List[Attribute[_]] =
def attributes(e: S3BatchEvent): Attributes =
S3BatchEventAttributes(e)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,55 +20,56 @@ import feral.lambda.events.DynamoDbRecord
import feral.lambda.events.S3BatchEvent
import feral.lambda.events.SqsRecord
import org.typelevel.otel4s.Attribute
import org.typelevel.otel4s.Attributes

import LambdaMessageAttributes._
import LambdaContextAttributes._

object SqsEventAttributes {
def apply(): List[Attribute[_]] =
List(
def apply(): Attributes =
Attributes(
FaasTrigger(FaasTriggerValue.Pubsub.value),
MessagingSystem("aws_sqs")
)
}

object SqsRecordAttributes {
def apply(e: SqsRecord): List[Attribute[_]] =
List(
def apply(e: SqsRecord): Attributes =
Attributes(
FaasTrigger(FaasTriggerValue.Pubsub.value),
MessagingOperation(MessagingOperationValue.Receive.value),
MessagingMessageId(e.messageId)
)
}

object DynamoDbStreamEventAttributes {
def apply(): List[Attribute[_]] =
List(
def apply(): Attributes =
Attributes(
FaasTrigger(FaasTriggerValue.Datasource.value),
MessagingSystem("aws_sqs")
)
}

object DynamoDbRecordAttributes {
def apply(e: DynamoDbRecord): List[Attribute[_]] =
List(
e.eventId.map(MessagingMessageId(_)),
Some(FaasTrigger(FaasTriggerValue.Datasource.value)),
Some(MessagingOperation(MessagingOperationValue.Receive.value))
).flatten
def apply(e: DynamoDbRecord): Attributes = {
Attributes(
FaasTrigger(FaasTriggerValue.Datasource.value),
MessagingOperation(MessagingOperationValue.Receive.value)
) ++ e.eventId.map(MessagingMessageId(_))
}
}

object ApiGatewayProxyEventAttributes {
def apply(): List[Attribute[_]] =
List(
def apply(): Attributes =
Attributes(
FaasTrigger(FaasTriggerValue.Http.value),
MessagingOperation(MessagingOperationValue.Receive.value)
)
}

object S3BatchEventAttributes {
def apply(e: S3BatchEvent): List[Attribute[_]] =
List(
def apply(e: S3BatchEvent): Attributes =
Attributes(
MessagingMessageId(e.invocationId),
FaasTrigger(FaasTriggerValue.Datasource.value),
MessagingOperation(MessagingOperationValue.Receive.value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@

package feral.lambda.otel4s

import org.typelevel.otel4s.Attribute
import org.typelevel.otel4s.Attributes
import org.typelevel.otel4s.trace.SpanKind

// TODO better name
protected trait EventSpanAttributes[E] {
def contextCarrier(e: E): Map[String, String]
def spanKind: SpanKind
def attributes(e: E): List[Attribute[_]]
def attributes(e: E): Attributes
}

protected object EventSpanAttributes {
Expand All @@ -32,7 +32,7 @@ protected object EventSpanAttributes {
def contextCarrier(e: E): Map[String, String] =
Map.empty
def spanKind: SpanKind = sk
def attributes(e: E): List[Attribute[_]] =
List.empty
def attributes(e: E): Attributes =
Attributes.empty
}
}

0 comments on commit 84d303b

Please sign in to comment.