Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
([#4058](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/4058))
- `opentelemetry-instrumentation-django`: Replace SpanAttributes with semconv constants where applicable
([#4059](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/4059))
- `opentelemetry-instrumentation-botocore`: Replace SpanAttributes with semconv constants where applicable
([#4063](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/4063))
- `opentelemetry-instrumentation-celery`: Replace SpanAttributes with semconv constants where applicable
([#4056](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/4056))
- `opentelemetry-instrumentation-confluent-kafka`: Replace SpanAttributes with semconv constants where applicable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,14 @@ def response_hook(span, service_name, operation_name, result):
from opentelemetry.semconv._incubating.attributes.cloud_attributes import (
CLOUD_REGION,
)
from opentelemetry.semconv.trace import SpanAttributes
from opentelemetry.semconv._incubating.attributes.http_attributes import (
HTTP_STATUS_CODE,
)
from opentelemetry.semconv._incubating.attributes.rpc_attributes import (
RPC_METHOD,
RPC_SERVICE,
RPC_SYSTEM,
)
from opentelemetry.trace import get_tracer
from opentelemetry.trace.span import Span

Expand Down Expand Up @@ -292,9 +299,9 @@ def _patched_api_call(self, original_func, instance, args, kwargs):
return original_func(*args, **kwargs)

attributes = {
SpanAttributes.RPC_SYSTEM: "aws-api",
SpanAttributes.RPC_SERVICE: call_context.service_id,
SpanAttributes.RPC_METHOD: call_context.operation,
RPC_SYSTEM: "aws-api",
RPC_SERVICE: call_context.service_id,
RPC_METHOD: call_context.operation,
CLOUD_REGION: call_context.region,
**get_server_attributes(call_context.endpoint_url),
}
Expand Down Expand Up @@ -390,7 +397,7 @@ def _apply_response_attributes(span: Span, result):

status_code = metadata.get("HTTPStatusCode")
if status_code is not None:
span.set_attribute(SpanAttributes.HTTP_STATUS_CODE, status_code)
span.set_attribute(HTTP_STATUS_CODE, status_code)


def _determine_call_context(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@
_BotocoreInstrumentorContext,
_BotoResultT,
)
from opentelemetry.semconv.trace import DbSystemValues, SpanAttributes
from opentelemetry.semconv._incubating.attributes import (
aws_attributes,
db_attributes,
)
from opentelemetry.semconv._incubating.attributes.net_attributes import (
NET_PEER_NAME,
)
from opentelemetry.trace.span import Span
from opentelemetry.util.types import AttributeValue

Expand Down Expand Up @@ -126,10 +132,10 @@ def add_response_attributes(

class _OpBatchGetItem(_DynamoDbOperation):
start_attributes = {
SpanAttributes.AWS_DYNAMODB_TABLE_NAMES: _REQ_REQITEMS_TABLE_NAMES,
aws_attributes.AWS_DYNAMODB_TABLE_NAMES: _REQ_REQITEMS_TABLE_NAMES,
}
response_attributes = {
SpanAttributes.AWS_DYNAMODB_CONSUMED_CAPACITY: _RES_CONSUMED_CAP,
aws_attributes.AWS_DYNAMODB_CONSUMED_CAPACITY: _RES_CONSUMED_CAP,
}

@classmethod
Expand All @@ -139,11 +145,11 @@ def operation_name(cls):

class _OpBatchWriteItem(_DynamoDbOperation):
start_attributes = {
SpanAttributes.AWS_DYNAMODB_TABLE_NAMES: _REQ_REQITEMS_TABLE_NAMES,
aws_attributes.AWS_DYNAMODB_TABLE_NAMES: _REQ_REQITEMS_TABLE_NAMES,
}
response_attributes = {
SpanAttributes.AWS_DYNAMODB_CONSUMED_CAPACITY: _RES_CONSUMED_CAP,
SpanAttributes.AWS_DYNAMODB_ITEM_COLLECTION_METRICS: _RES_ITEM_COL_METRICS,
aws_attributes.AWS_DYNAMODB_CONSUMED_CAPACITY: _RES_CONSUMED_CAP,
aws_attributes.AWS_DYNAMODB_ITEM_COLLECTION_METRICS: _RES_ITEM_COL_METRICS,
}

@classmethod
Expand All @@ -153,13 +159,13 @@ def operation_name(cls):

class _OpCreateTable(_DynamoDbOperation):
start_attributes = {
SpanAttributes.AWS_DYNAMODB_TABLE_NAMES: _REQ_TABLE_NAME,
aws_attributes.AWS_DYNAMODB_TABLE_NAMES: _REQ_TABLE_NAME,
}
request_attributes = {
SpanAttributes.AWS_DYNAMODB_GLOBAL_SECONDARY_INDEXES: _REQ_GLOBAL_SEC_INDEXES,
SpanAttributes.AWS_DYNAMODB_LOCAL_SECONDARY_INDEXES: _REQ_LOCAL_SEC_INDEXES,
SpanAttributes.AWS_DYNAMODB_PROVISIONED_READ_CAPACITY: _REQ_PROV_READ_CAP,
SpanAttributes.AWS_DYNAMODB_PROVISIONED_WRITE_CAPACITY: _REQ_PROV_WRITE_CAP,
aws_attributes.AWS_DYNAMODB_GLOBAL_SECONDARY_INDEXES: _REQ_GLOBAL_SEC_INDEXES,
aws_attributes.AWS_DYNAMODB_LOCAL_SECONDARY_INDEXES: _REQ_LOCAL_SEC_INDEXES,
aws_attributes.AWS_DYNAMODB_PROVISIONED_READ_CAPACITY: _REQ_PROV_READ_CAP,
aws_attributes.AWS_DYNAMODB_PROVISIONED_WRITE_CAPACITY: _REQ_PROV_WRITE_CAP,
}

@classmethod
Expand All @@ -169,11 +175,11 @@ def operation_name(cls):

class _OpDeleteItem(_DynamoDbOperation):
start_attributes = {
SpanAttributes.AWS_DYNAMODB_TABLE_NAMES: _REQ_TABLE_NAME,
aws_attributes.AWS_DYNAMODB_TABLE_NAMES: _REQ_TABLE_NAME,
}
response_attributes = {
SpanAttributes.AWS_DYNAMODB_CONSUMED_CAPACITY: _RES_CONSUMED_CAP_SINGLE,
SpanAttributes.AWS_DYNAMODB_ITEM_COLLECTION_METRICS: _RES_ITEM_COL_METRICS,
aws_attributes.AWS_DYNAMODB_CONSUMED_CAPACITY: _RES_CONSUMED_CAP_SINGLE,
aws_attributes.AWS_DYNAMODB_ITEM_COLLECTION_METRICS: _RES_ITEM_COL_METRICS,
}

@classmethod
Expand All @@ -183,7 +189,7 @@ def operation_name(cls):

class _OpDeleteTable(_DynamoDbOperation):
start_attributes = {
SpanAttributes.AWS_DYNAMODB_TABLE_NAMES: _REQ_TABLE_NAME,
aws_attributes.AWS_DYNAMODB_TABLE_NAMES: _REQ_TABLE_NAME,
}

@classmethod
Expand All @@ -193,7 +199,7 @@ def operation_name(cls):

class _OpDescribeTable(_DynamoDbOperation):
start_attributes = {
SpanAttributes.AWS_DYNAMODB_TABLE_NAMES: _REQ_TABLE_NAME,
aws_attributes.AWS_DYNAMODB_TABLE_NAMES: _REQ_TABLE_NAME,
}

@classmethod
Expand All @@ -203,14 +209,14 @@ def operation_name(cls):

class _OpGetItem(_DynamoDbOperation):
start_attributes = {
SpanAttributes.AWS_DYNAMODB_TABLE_NAMES: _REQ_TABLE_NAME,
aws_attributes.AWS_DYNAMODB_TABLE_NAMES: _REQ_TABLE_NAME,
}
request_attributes = {
SpanAttributes.AWS_DYNAMODB_CONSISTENT_READ: _REQ_CONSISTENT_READ,
SpanAttributes.AWS_DYNAMODB_PROJECTION: _REQ_PROJECTION,
aws_attributes.AWS_DYNAMODB_CONSISTENT_READ: _REQ_CONSISTENT_READ,
aws_attributes.AWS_DYNAMODB_PROJECTION: _REQ_PROJECTION,
}
response_attributes = {
SpanAttributes.AWS_DYNAMODB_CONSUMED_CAPACITY: _RES_CONSUMED_CAP_SINGLE,
aws_attributes.AWS_DYNAMODB_CONSUMED_CAPACITY: _RES_CONSUMED_CAP_SINGLE,
}

@classmethod
Expand All @@ -220,14 +226,14 @@ def operation_name(cls):

class _OpListTables(_DynamoDbOperation):
request_attributes = {
SpanAttributes.AWS_DYNAMODB_EXCLUSIVE_START_TABLE: (
aws_attributes.AWS_DYNAMODB_EXCLUSIVE_START_TABLE: (
"ExclusiveStartTableName",
None,
),
SpanAttributes.AWS_DYNAMODB_LIMIT: _REQ_LIMIT,
aws_attributes.AWS_DYNAMODB_LIMIT: _REQ_LIMIT,
}
response_attributes = {
SpanAttributes.AWS_DYNAMODB_TABLE_COUNT: (
aws_attributes.AWS_DYNAMODB_TABLE_COUNT: (
"TableNames",
_conv_val_to_len,
),
Expand All @@ -240,11 +246,11 @@ def operation_name(cls):

class _OpPutItem(_DynamoDbOperation):
start_attributes = {
SpanAttributes.AWS_DYNAMODB_TABLE_NAMES: _REQ_TABLE_NAME
aws_attributes.AWS_DYNAMODB_TABLE_NAMES: _REQ_TABLE_NAME
}
response_attributes = {
SpanAttributes.AWS_DYNAMODB_CONSUMED_CAPACITY: _RES_CONSUMED_CAP_SINGLE,
SpanAttributes.AWS_DYNAMODB_ITEM_COLLECTION_METRICS: _RES_ITEM_COL_METRICS,
aws_attributes.AWS_DYNAMODB_CONSUMED_CAPACITY: _RES_CONSUMED_CAP_SINGLE,
aws_attributes.AWS_DYNAMODB_ITEM_COLLECTION_METRICS: _RES_ITEM_COL_METRICS,
}

@classmethod
Expand All @@ -254,19 +260,19 @@ def operation_name(cls):

class _OpQuery(_DynamoDbOperation):
start_attributes = {
SpanAttributes.AWS_DYNAMODB_TABLE_NAMES: _REQ_TABLE_NAME,
aws_attributes.AWS_DYNAMODB_TABLE_NAMES: _REQ_TABLE_NAME,
}
request_attributes = {
SpanAttributes.AWS_DYNAMODB_SCAN_FORWARD: ("ScanIndexForward", None),
SpanAttributes.AWS_DYNAMODB_ATTRIBUTES_TO_GET: _REQ_ATTRS_TO_GET,
SpanAttributes.AWS_DYNAMODB_CONSISTENT_READ: _REQ_CONSISTENT_READ,
SpanAttributes.AWS_DYNAMODB_INDEX_NAME: _REQ_INDEX_NAME,
SpanAttributes.AWS_DYNAMODB_LIMIT: _REQ_LIMIT,
SpanAttributes.AWS_DYNAMODB_PROJECTION: _REQ_PROJECTION,
SpanAttributes.AWS_DYNAMODB_SELECT: _REQ_SELECT,
aws_attributes.AWS_DYNAMODB_SCAN_FORWARD: ("ScanIndexForward", None),
aws_attributes.AWS_DYNAMODB_ATTRIBUTES_TO_GET: _REQ_ATTRS_TO_GET,
aws_attributes.AWS_DYNAMODB_CONSISTENT_READ: _REQ_CONSISTENT_READ,
aws_attributes.AWS_DYNAMODB_INDEX_NAME: _REQ_INDEX_NAME,
aws_attributes.AWS_DYNAMODB_LIMIT: _REQ_LIMIT,
aws_attributes.AWS_DYNAMODB_PROJECTION: _REQ_PROJECTION,
aws_attributes.AWS_DYNAMODB_SELECT: _REQ_SELECT,
}
response_attributes = {
SpanAttributes.AWS_DYNAMODB_CONSUMED_CAPACITY: _RES_CONSUMED_CAP_SINGLE,
aws_attributes.AWS_DYNAMODB_CONSUMED_CAPACITY: _RES_CONSUMED_CAP_SINGLE,
}

@classmethod
Expand All @@ -276,22 +282,22 @@ def operation_name(cls):

class _OpScan(_DynamoDbOperation):
start_attributes = {
SpanAttributes.AWS_DYNAMODB_TABLE_NAMES: _REQ_TABLE_NAME,
aws_attributes.AWS_DYNAMODB_TABLE_NAMES: _REQ_TABLE_NAME,
}
request_attributes = {
SpanAttributes.AWS_DYNAMODB_SEGMENT: ("Segment", None),
SpanAttributes.AWS_DYNAMODB_TOTAL_SEGMENTS: ("TotalSegments", None),
SpanAttributes.AWS_DYNAMODB_ATTRIBUTES_TO_GET: _REQ_ATTRS_TO_GET,
SpanAttributes.AWS_DYNAMODB_CONSISTENT_READ: _REQ_CONSISTENT_READ,
SpanAttributes.AWS_DYNAMODB_INDEX_NAME: _REQ_INDEX_NAME,
SpanAttributes.AWS_DYNAMODB_LIMIT: _REQ_LIMIT,
SpanAttributes.AWS_DYNAMODB_PROJECTION: _REQ_PROJECTION,
SpanAttributes.AWS_DYNAMODB_SELECT: _REQ_SELECT,
aws_attributes.AWS_DYNAMODB_SEGMENT: ("Segment", None),
aws_attributes.AWS_DYNAMODB_TOTAL_SEGMENTS: ("TotalSegments", None),
aws_attributes.AWS_DYNAMODB_ATTRIBUTES_TO_GET: _REQ_ATTRS_TO_GET,
aws_attributes.AWS_DYNAMODB_CONSISTENT_READ: _REQ_CONSISTENT_READ,
aws_attributes.AWS_DYNAMODB_INDEX_NAME: _REQ_INDEX_NAME,
aws_attributes.AWS_DYNAMODB_LIMIT: _REQ_LIMIT,
aws_attributes.AWS_DYNAMODB_PROJECTION: _REQ_PROJECTION,
aws_attributes.AWS_DYNAMODB_SELECT: _REQ_SELECT,
}
response_attributes = {
SpanAttributes.AWS_DYNAMODB_COUNT: ("Count", None),
SpanAttributes.AWS_DYNAMODB_SCANNED_COUNT: ("ScannedCount", None),
SpanAttributes.AWS_DYNAMODB_CONSUMED_CAPACITY: _RES_CONSUMED_CAP_SINGLE,
aws_attributes.AWS_DYNAMODB_COUNT: ("Count", None),
aws_attributes.AWS_DYNAMODB_SCANNED_COUNT: ("ScannedCount", None),
aws_attributes.AWS_DYNAMODB_CONSUMED_CAPACITY: _RES_CONSUMED_CAP_SINGLE,
}

@classmethod
Expand All @@ -301,11 +307,11 @@ def operation_name(cls):

class _OpUpdateItem(_DynamoDbOperation):
start_attributes = {
SpanAttributes.AWS_DYNAMODB_TABLE_NAMES: _REQ_TABLE_NAME,
aws_attributes.AWS_DYNAMODB_TABLE_NAMES: _REQ_TABLE_NAME,
}
response_attributes = {
SpanAttributes.AWS_DYNAMODB_CONSUMED_CAPACITY: _RES_CONSUMED_CAP_SINGLE,
SpanAttributes.AWS_DYNAMODB_ITEM_COLLECTION_METRICS: _RES_ITEM_COL_METRICS,
aws_attributes.AWS_DYNAMODB_CONSUMED_CAPACITY: _RES_CONSUMED_CAP_SINGLE,
aws_attributes.AWS_DYNAMODB_ITEM_COLLECTION_METRICS: _RES_ITEM_COL_METRICS,
}

@classmethod
Expand All @@ -315,19 +321,19 @@ def operation_name(cls):

class _OpUpdateTable(_DynamoDbOperation):
start_attributes = {
SpanAttributes.AWS_DYNAMODB_TABLE_NAMES: _REQ_TABLE_NAME,
aws_attributes.AWS_DYNAMODB_TABLE_NAMES: _REQ_TABLE_NAME,
}
request_attributes = {
SpanAttributes.AWS_DYNAMODB_ATTRIBUTE_DEFINITIONS: (
aws_attributes.AWS_DYNAMODB_ATTRIBUTE_DEFINITIONS: (
"AttributeDefinitions",
_conv_list_to_json_list,
),
SpanAttributes.AWS_DYNAMODB_GLOBAL_SECONDARY_INDEX_UPDATES: (
aws_attributes.AWS_DYNAMODB_GLOBAL_SECONDARY_INDEX_UPDATES: (
"GlobalSecondaryIndexUpdates",
_conv_list_to_json_list,
),
SpanAttributes.AWS_DYNAMODB_PROVISIONED_READ_CAPACITY: _REQ_PROV_READ_CAP,
SpanAttributes.AWS_DYNAMODB_PROVISIONED_WRITE_CAPACITY: _REQ_PROV_WRITE_CAP,
aws_attributes.AWS_DYNAMODB_PROVISIONED_READ_CAPACITY: _REQ_PROV_READ_CAP,
aws_attributes.AWS_DYNAMODB_PROVISIONED_WRITE_CAPACITY: _REQ_PROV_WRITE_CAP,
}

@classmethod
Expand All @@ -354,9 +360,11 @@ def __init__(self, call_context: _AwsSdkCallContext):
self._op = _OPERATION_MAPPING.get(call_context.operation)

def extract_attributes(self, attributes: _AttributeMapT):
attributes[SpanAttributes.DB_SYSTEM] = DbSystemValues.DYNAMODB.value
attributes[SpanAttributes.DB_OPERATION] = self._call_context.operation
attributes[SpanAttributes.NET_PEER_NAME] = self._get_peer_name()
attributes[db_attributes.DB_SYSTEM] = (
db_attributes.DbSystemValues.DYNAMODB.value
)
attributes[db_attributes.DB_OPERATION] = self._call_context.operation
attributes[NET_PEER_NAME] = self._get_peer_name()

if self._op is None:
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@
_BotocoreInstrumentorContext,
)
from opentelemetry.propagate import inject
from opentelemetry.semconv.trace import SpanAttributes
from opentelemetry.semconv._incubating.attributes.faas_attributes import (
FAAS_INVOKED_NAME,
FAAS_INVOKED_PROVIDER,
FAAS_INVOKED_REGION,
)
from opentelemetry.trace.span import Span


Expand Down Expand Up @@ -62,11 +66,9 @@ def operation_name(cls):
def extract_attributes(
cls, call_context: _AwsSdkCallContext, attributes: _AttributeMapT
):
attributes[SpanAttributes.FAAS_INVOKED_PROVIDER] = "aws"
attributes[SpanAttributes.FAAS_INVOKED_NAME] = (
cls._parse_function_name(call_context)
)
attributes[SpanAttributes.FAAS_INVOKED_REGION] = call_context.region
attributes[FAAS_INVOKED_PROVIDER] = "aws"
attributes[FAAS_INVOKED_NAME] = cls._parse_function_name(call_context)
attributes[FAAS_INVOKED_REGION] = call_context.region

@classmethod
def _parse_function_name(cls, call_context: _AwsSdkCallContext):
Expand Down
Loading