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

Use semconv creation functions #3369

Merged
merged 4 commits into from
Feb 8, 2023
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
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
### Fixed

- The GCE detector in `go.opentelemetry.io/contrib/detectors/gcp` includes the "cloud.region" attribute when appropriate. (#3367)
- The span name of producer spans from `go.opentelemetry.io/contrib/instrumentation/github.com/Shopify/sarama/otelsarama` is corrected to use `publish` instead of `send`. (#3396)
- Attribute types are corrected in `go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws`. (#3396)
- `aws.dynamodb.table_names` is now a string slice value.
- `aws.dynamodb.global_secondary_indexes` is now a string slice value.
- `aws.dynamodb.local_secondary_indexes` is now a string slice value.
- `aws.dynamodb.attribute_definitions` is now a string slice value.
- `aws.dynamodb.global_secondary_index_updates` is now a string slice value.
- `aws.dynamodb.provisioned_read_capacity` is now a `float64` value.
- `aws.dynamodb.provisioned_write_capacity` is now a `float64` value.

## [1.13.0/0.38.0/0.7.0] - 2023-01-30

Expand Down
12 changes: 6 additions & 6 deletions detectors/aws/ec2/ec2.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,12 @@ func (detector *resourceDetector) Detect(ctx context.Context) (*resource.Resourc
attributes := []attribute.KeyValue{
semconv.CloudProviderAWS,
semconv.CloudPlatformAWSEC2,
semconv.CloudRegionKey.String(doc.Region),
semconv.CloudAvailabilityZoneKey.String(doc.AvailabilityZone),
semconv.CloudAccountIDKey.String(doc.AccountID),
semconv.HostIDKey.String(doc.InstanceID),
semconv.HostImageIDKey.String(doc.ImageID),
semconv.HostTypeKey.String(doc.InstanceType),
semconv.CloudRegion(doc.Region),
semconv.CloudAvailabilityZone(doc.AvailabilityZone),
semconv.CloudAccountID(doc.AccountID),
semconv.HostID(doc.InstanceID),
semconv.HostImageID(doc.ImageID),
semconv.HostType(doc.InstanceType),
}

m := &metadata{client: client}
Expand Down
26 changes: 13 additions & 13 deletions detectors/aws/ec2/ec2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ func TestAWS_Detect(t *testing.T) {
usWestIDLabels := []attribute.KeyValue{
semconv.CloudProviderAWS,
semconv.CloudPlatformAWSEC2,
semconv.CloudRegionKey.String("us-west-2"),
semconv.CloudAvailabilityZoneKey.String("us-west-2b"),
semconv.CloudAccountIDKey.String("123456789012"),
semconv.HostIDKey.String("i-1234567890abcdef0"),
semconv.HostImageIDKey.String("ami-5fb8c835"),
semconv.HostTypeKey.String("t2.micro"),
semconv.CloudRegion("us-west-2"),
semconv.CloudAvailabilityZone("us-west-2b"),
semconv.CloudAccountID("123456789012"),
semconv.HostID("i-1234567890abcdef0"),
semconv.HostImageID("ami-5fb8c835"),
semconv.HostType("t2.micro"),
}

testTable := map[string]struct {
Expand Down Expand Up @@ -139,13 +139,13 @@ func TestAWS_Detect(t *testing.T) {
semconv.SchemaURL,
semconv.CloudProviderAWS,
semconv.CloudPlatformAWSEC2,
semconv.CloudRegionKey.String("us-west-2"),
semconv.CloudAvailabilityZoneKey.String("us-west-2b"),
semconv.CloudAccountIDKey.String("123456789012"),
semconv.HostIDKey.String("i-1234567890abcdef0"),
semconv.HostImageIDKey.String("ami-5fb8c835"),
semconv.HostNameKey.String("ip-12-34-56-78.us-west-2.compute.internal"),
semconv.HostTypeKey.String("t2.micro"),
semconv.CloudRegion("us-west-2"),
semconv.CloudAvailabilityZone("us-west-2b"),
semconv.CloudAccountID("123456789012"),
semconv.HostID("i-1234567890abcdef0"),
semconv.HostImageID("ami-5fb8c835"),
semconv.HostName("ip-12-34-56-78.us-west-2.compute.internal"),
semconv.HostType("t2.micro"),
)},
},
}
Expand Down
22 changes: 11 additions & 11 deletions detectors/aws/ecs/ecs.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ func (detector *resourceDetector) Detect(ctx context.Context) (*resource.Resourc
attributes := []attribute.KeyValue{
semconv.CloudProviderAWS,
semconv.CloudPlatformAWSECS,
semconv.ContainerNameKey.String(hostName),
semconv.ContainerIDKey.String(containerID),
semconv.ContainerName(hostName),
semconv.ContainerID(containerID),
}

if len(metadataURIV4) > 0 {
Expand All @@ -104,7 +104,7 @@ func (detector *resourceDetector) Detect(ctx context.Context) (*resource.Resourc
}
attributes = append(
attributes,
semconv.AWSECSContainerARNKey.String(containerMetadata.ContainerARN),
semconv.AWSECSContainerARN(containerMetadata.ContainerARN),
)

taskMetadata, err := ecsmetadata.GetTaskV4(ctx, &http.Client{})
Expand All @@ -129,11 +129,11 @@ func (detector *resourceDetector) Detect(ctx context.Context) (*resource.Resourc

attributes = append(
attributes,
semconv.AWSECSClusterARNKey.String(clusterArn),
semconv.AWSECSClusterARN(clusterArn),
semconv.AWSECSLaunchtypeKey.String(strings.ToLower(taskMetadata.LaunchType)),
semconv.AWSECSTaskARNKey.String(taskMetadata.TaskARN),
semconv.AWSECSTaskFamilyKey.String(taskMetadata.Family),
semconv.AWSECSTaskRevisionKey.String(taskMetadata.Revision),
semconv.AWSECSTaskARN(taskMetadata.TaskARN),
semconv.AWSECSTaskFamily(taskMetadata.Family),
semconv.AWSECSTaskRevision(taskMetadata.Revision),
)
}

Expand Down Expand Up @@ -166,10 +166,10 @@ func (detector *resourceDetector) getLogsAttributes(metadata *ecsmetadata.Contai
awsAccount := r.FindStringSubmatch(containerArn)[1]

return []attribute.KeyValue{
semconv.AWSLogGroupNamesKey.String(logsOptions.AwsLogsGroup),
semconv.AWSLogGroupARNsKey.String(fmt.Sprintf("arn:aws:logs:%s:%s:log-group:%s:*", logsRegion, awsAccount, logsOptions.AwsLogsGroup)),
semconv.AWSLogStreamNamesKey.String(logsOptions.AwsLogsStream),
semconv.AWSLogStreamARNsKey.String(fmt.Sprintf("arn:aws:logs:%s:%s:log-group:%s:log-stream:%s", logsRegion, awsAccount, logsOptions.AwsLogsGroup, logsOptions.AwsLogsStream)),
semconv.AWSLogGroupNames(logsOptions.AwsLogsGroup),
semconv.AWSLogGroupARNs(fmt.Sprintf("arn:aws:logs:%s:%s:log-group:%s:*", logsRegion, awsAccount, logsOptions.AwsLogsGroup)),
semconv.AWSLogStreamNames(logsOptions.AwsLogsStream),
semconv.AWSLogStreamARNs(fmt.Sprintf("arn:aws:logs:%s:%s:log-group:%s:log-stream:%s", logsRegion, awsAccount, logsOptions.AwsLogsGroup, logsOptions.AwsLogsStream)),
}, nil
}

Expand Down
8 changes: 4 additions & 4 deletions detectors/aws/ecs/ecs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ func TestDetectV3(t *testing.T) {
attributes := []attribute.KeyValue{
semconv.CloudProviderAWS,
semconv.CloudPlatformAWSECS,
semconv.ContainerNameKey.String("container-Name"),
semconv.ContainerIDKey.String("0123456789A"),
semconv.ContainerName("container-Name"),
semconv.ContainerID("0123456789A"),
}
expectedResource := resource.NewWithAttributes(semconv.SchemaURL, attributes...)
detector := &resourceDetector{utils: detectorUtils}
Expand All @@ -78,8 +78,8 @@ func TestDetectCannotReadContainerID(t *testing.T) {
attributes := []attribute.KeyValue{
semconv.CloudProviderAWS,
semconv.CloudPlatformAWSECS,
semconv.ContainerNameKey.String("container-Name"),
semconv.ContainerIDKey.String(""),
semconv.ContainerName("container-Name"),
semconv.ContainerID(""),
}
expectedResource := resource.NewWithAttributes(semconv.SchemaURL, attributes...)
detector := &resourceDetector{utils: detectorUtils}
Expand Down
44 changes: 22 additions & 22 deletions detectors/aws/ecs/test/ecs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,21 +67,21 @@ func TestDetectV4LaunchTypeEc2(t *testing.T) {
attributes := []attribute.KeyValue{
semconv.CloudProviderAWS,
semconv.CloudPlatformAWSECS,
semconv.ContainerNameKey.String(hostname),
semconv.ContainerName(hostname),
// We are not running the test in an actual container,
// the container id is tested with mocks of the cgroup
// file in the unit tests
semconv.ContainerIDKey.String(""),
semconv.AWSECSContainerARNKey.String("arn:aws:ecs:us-west-2:111122223333:container/0206b271-b33f-47ab-86c6-a0ba208a70a9"),
semconv.AWSECSClusterARNKey.String("arn:aws:ecs:us-west-2:111122223333:cluster/default"),
semconv.ContainerID(""),
semconv.AWSECSContainerARN("arn:aws:ecs:us-west-2:111122223333:container/0206b271-b33f-47ab-86c6-a0ba208a70a9"),
semconv.AWSECSClusterARN("arn:aws:ecs:us-west-2:111122223333:cluster/default"),
semconv.AWSECSLaunchtypeKey.String("ec2"),
semconv.AWSECSTaskARNKey.String("arn:aws:ecs:us-west-2:111122223333:task/default/158d1c8083dd49d6b527399fd6414f5c"),
semconv.AWSECSTaskFamilyKey.String("curltest"),
semconv.AWSECSTaskRevisionKey.String("26"),
semconv.AWSLogGroupNamesKey.String("/ecs/metadata"),
semconv.AWSLogGroupARNsKey.String("arn:aws:logs:us-west-2:111122223333:log-group:/ecs/metadata:*"),
semconv.AWSLogStreamNamesKey.String("ecs/curl/8f03e41243824aea923aca126495f665"),
semconv.AWSLogStreamARNsKey.String("arn:aws:logs:us-west-2:111122223333:log-group:/ecs/metadata:log-stream:ecs/curl/8f03e41243824aea923aca126495f665"),
semconv.AWSECSTaskARN("arn:aws:ecs:us-west-2:111122223333:task/default/158d1c8083dd49d6b527399fd6414f5c"),
semconv.AWSECSTaskFamily("curltest"),
semconv.AWSECSTaskRevision("26"),
semconv.AWSLogGroupNames("/ecs/metadata"),
semconv.AWSLogGroupARNs("arn:aws:logs:us-west-2:111122223333:log-group:/ecs/metadata:*"),
semconv.AWSLogStreamNames("ecs/curl/8f03e41243824aea923aca126495f665"),
semconv.AWSLogStreamARNs("arn:aws:logs:us-west-2:111122223333:log-group:/ecs/metadata:log-stream:ecs/curl/8f03e41243824aea923aca126495f665"),
}
expectedResource := resource.NewWithAttributes(semconv.SchemaURL, attributes...)
detector := ecs.NewResourceDetector()
Expand Down Expand Up @@ -124,21 +124,21 @@ func TestDetectV4LaunchTypeFargate(t *testing.T) {
attributes := []attribute.KeyValue{
semconv.CloudProviderAWS,
semconv.CloudPlatformAWSECS,
semconv.ContainerNameKey.String(hostname),
semconv.ContainerName(hostname),
// We are not running the test in an actual container,
// the container id is tested with mocks of the cgroup
// file in the unit tests
semconv.ContainerIDKey.String(""),
semconv.AWSECSContainerARNKey.String("arn:aws:ecs:us-west-2:111122223333:container/05966557-f16c-49cb-9352-24b3a0dcd0e1"),
semconv.AWSECSClusterARNKey.String("arn:aws:ecs:us-west-2:111122223333:cluster/default"),
semconv.ContainerID(""),
semconv.AWSECSContainerARN("arn:aws:ecs:us-west-2:111122223333:container/05966557-f16c-49cb-9352-24b3a0dcd0e1"),
semconv.AWSECSClusterARN("arn:aws:ecs:us-west-2:111122223333:cluster/default"),
semconv.AWSECSLaunchtypeKey.String("fargate"),
semconv.AWSECSTaskARNKey.String("arn:aws:ecs:us-west-2:111122223333:task/default/e9028f8d5d8e4f258373e7b93ce9a3c3"),
semconv.AWSECSTaskFamilyKey.String("curltest"),
semconv.AWSECSTaskRevisionKey.String("3"),
semconv.AWSLogGroupNamesKey.String("/ecs/containerlogs"),
semconv.AWSLogGroupARNsKey.String("arn:aws:logs:us-west-2:111122223333:log-group:/ecs/containerlogs:*"),
semconv.AWSLogStreamNamesKey.String("ecs/curl/cd189a933e5849daa93386466019ab50"),
semconv.AWSLogStreamARNsKey.String("arn:aws:logs:us-west-2:111122223333:log-group:/ecs/containerlogs:log-stream:ecs/curl/cd189a933e5849daa93386466019ab50"),
semconv.AWSECSTaskARN("arn:aws:ecs:us-west-2:111122223333:task/default/e9028f8d5d8e4f258373e7b93ce9a3c3"),
semconv.AWSECSTaskFamily("curltest"),
semconv.AWSECSTaskRevision("3"),
semconv.AWSLogGroupNames("/ecs/containerlogs"),
semconv.AWSLogGroupARNs("arn:aws:logs:us-west-2:111122223333:log-group:/ecs/containerlogs:*"),
semconv.AWSLogStreamNames("ecs/curl/cd189a933e5849daa93386466019ab50"),
semconv.AWSLogStreamARNs("arn:aws:logs:us-west-2:111122223333:log-group:/ecs/containerlogs:log-stream:ecs/curl/cd189a933e5849daa93386466019ab50"),
}
expectedResource := resource.NewWithAttributes(semconv.SchemaURL, attributes...)
detector := ecs.NewResourceDetector()
Expand Down
4 changes: 2 additions & 2 deletions detectors/aws/eks/detector.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func (detector *resourceDetector) Detect(ctx context.Context) (*resource.Resourc
return nil, err
}
if clusterName != "" {
attributes = append(attributes, semconv.K8SClusterNameKey.String(clusterName))
attributes = append(attributes, semconv.K8SClusterName(clusterName))
}

// Get containerID and append to attributes
Expand All @@ -108,7 +108,7 @@ func (detector *resourceDetector) Detect(ctx context.Context) (*resource.Resourc
return nil, err
}
if containerID != "" {
attributes = append(attributes, semconv.ContainerIDKey.String(containerID))
attributes = append(attributes, semconv.ContainerID(containerID))
}

// Return new resource object with clusterName and containerID as attributes
Expand Down
4 changes: 2 additions & 2 deletions detectors/aws/eks/detector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ func TestEks(t *testing.T) {
eksResourceLabels := []attribute.KeyValue{
semconv.CloudProviderAWS,
semconv.CloudPlatformAWSEKS,
semconv.K8SClusterNameKey.String("my-cluster"),
semconv.ContainerIDKey.String("0123456789A"),
semconv.K8SClusterName("my-cluster"),
semconv.ContainerID("0123456789A"),
}
expectedResource := resource.NewWithAttributes(semconv.SchemaURL, eksResourceLabels...)

Expand Down
10 changes: 5 additions & 5 deletions detectors/aws/lambda/detector.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,16 @@ func (detector *resourceDetector) Detect(context.Context) (*resource.Resource, e

attrs := []attribute.KeyValue{
semconv.CloudProviderAWS,
semconv.CloudRegionKey.String(awsRegion),
semconv.FaaSInstanceKey.String(instance),
semconv.FaaSNameKey.String(lambdaName),
semconv.FaaSVersionKey.String(functionVersion),
semconv.CloudRegion(awsRegion),
semconv.FaaSInstance(instance),
semconv.FaaSName(lambdaName),
semconv.FaaSVersion(functionVersion),
}

maxMemoryStr := os.Getenv(lambdaMemoryLimitEnvVar)
maxMemory, err := strconv.Atoi(maxMemoryStr)
if err == nil {
attrs = append(attrs, semconv.FaaSMaxMemoryKey.Int(maxMemory))
attrs = append(attrs, semconv.FaaSMaxMemory(maxMemory))
}

return resource.NewWithAttributes(semconv.SchemaURL, attrs...), nil
Expand Down
10 changes: 5 additions & 5 deletions detectors/aws/lambda/detector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ func TestDetectSuccess(t *testing.T) {

attributes := []attribute.KeyValue{
semconv.CloudProviderAWS,
semconv.CloudRegionKey.String("us-texas-1"),
semconv.FaaSNameKey.String("testFunction"),
semconv.FaaSVersionKey.String("$LATEST"),
semconv.FaaSInstanceKey.String("2023/01/01/[$LATEST]5d1edb9e525d486696cf01a3503487bc"),
semconv.FaaSMaxMemoryKey.Int(128),
semconv.CloudRegion("us-texas-1"),
semconv.FaaSName("testFunction"),
semconv.FaaSVersion("$LATEST"),
semconv.FaaSInstance("2023/01/01/[$LATEST]5d1edb9e525d486696cf01a3503487bc"),
semconv.FaaSMaxMemory(128),
}
expectedResource := resource.NewWithAttributes(semconv.SchemaURL, attributes...)
detector := resourceDetector{}
Expand Down
6 changes: 3 additions & 3 deletions detectors/gcp/cloud-function.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ func (f *cloudFunction) Detect(ctx context.Context) (*resource.Resource, error)
attributes := []attribute.KeyValue{
semconv.CloudProviderGCP,
semconv.CloudPlatformGCPCloudFunctions,
semconv.FaaSNameKey.String(functionName),
semconv.CloudAccountIDKey.String(projectID),
semconv.CloudRegionKey.String(region),
semconv.FaaSName(functionName),
semconv.CloudAccountID(projectID),
semconv.CloudRegion(region),
}
return resource.NewWithAttributes(semconv.SchemaURL, attributes...), nil
}
Expand Down
6 changes: 3 additions & 3 deletions detectors/gcp/cloud-function_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,9 @@ func TestCloudFunctionDetect(t *testing.T) {
res: resource.NewSchemaless([]attribute.KeyValue{
semconv.CloudProviderGCP,
semconv.CloudPlatformGCPCloudFunctions,
semconv.FaaSNameKey.String(functionName),
semconv.CloudAccountIDKey.String(projectIDValue),
semconv.CloudRegionKey.String(regionValue),
semconv.FaaSName(functionName),
semconv.CloudAccountID(projectIDValue),
semconv.CloudRegion(regionValue),
}...),
err: nil,
},
Expand Down
10 changes: 5 additions & 5 deletions detectors/gcp/cloud-run.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,35 +82,35 @@ func (c *CloudRun) Detect(ctx context.Context) (*resource.Resource, error) {

attributes := []attribute.KeyValue{
semconv.CloudProviderGCP,
semconv.ServiceNamespaceKey.String(serviceNamespace),
semconv.ServiceNamespace(serviceNamespace),
}

var errInfo []string

if projectID, err := c.mc.ProjectID(); hasProblem(err) {
errInfo = append(errInfo, err.Error())
} else if projectID != "" {
attributes = append(attributes, semconv.CloudAccountIDKey.String(projectID))
attributes = append(attributes, semconv.CloudAccountID(projectID))
}

if region, err := c.cloudRegion(ctx); hasProblem(err) {
errInfo = append(errInfo, err.Error())
} else if region != "" {
attributes = append(attributes, semconv.CloudRegionKey.String(region))
attributes = append(attributes, semconv.CloudRegion(region))
}

if instanceID, err := c.mc.InstanceID(); hasProblem(err) {
errInfo = append(errInfo, err.Error())
} else if instanceID != "" {
attributes = append(attributes, semconv.ServiceInstanceIDKey.String(instanceID))
attributes = append(attributes, semconv.ServiceInstanceID(instanceID))
}

// Part of Cloud Run container runtime contract.
// See https://cloud.google.com/run/docs/reference/container-contract
if service := c.getenv("K_SERVICE"); service == "" {
errInfo = append(errInfo, "envvar K_SERVICE contains empty string.")
} else {
attributes = append(attributes, semconv.ServiceNameKey.String(service))
attributes = append(attributes, semconv.ServiceName(service))
}
res := resource.NewWithAttributes(semconv.SchemaURL, attributes...)

Expand Down
8 changes: 4 additions & 4 deletions detectors/gcp/detector.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ func (r *resourceBuilder) add(key attribute.Key, detect func() (string, error))
// zoneAndRegion functions are expected to return zone, region, err.
func (r *resourceBuilder) addZoneAndRegion(detect func() (string, string, error)) {
if zone, region, err := detect(); err == nil {
r.attrs = append(r.attrs, semconv.CloudAvailabilityZoneKey.String(zone))
r.attrs = append(r.attrs, semconv.CloudRegionKey.String(region))
r.attrs = append(r.attrs, semconv.CloudAvailabilityZone(zone))
r.attrs = append(r.attrs, semconv.CloudRegion(region))
} else {
r.errs = append(r.errs, err)
}
Expand All @@ -122,9 +122,9 @@ func (r *resourceBuilder) addZoneOrRegion(detect func() (string, gcp.LocationTyp
if v, locType, err := detect(); err == nil {
switch locType {
case gcp.Zone:
r.attrs = append(r.attrs, semconv.CloudAvailabilityZoneKey.String(v))
r.attrs = append(r.attrs, semconv.CloudAvailabilityZone(v))
case gcp.Region:
r.attrs = append(r.attrs, semconv.CloudRegionKey.String(v))
r.attrs = append(r.attrs, semconv.CloudRegion(v))
default:
r.errs = append(r.errs, fmt.Errorf("location must be zone or region. Got %v", locType))
}
Expand Down
Loading