Skip to content

[exporter/azuremonitor] Azure Container Apps - cloud_RoleInstance #47657

@davidvesp

Description

@davidvesp

Component(s)

No response

What happened?

Description

We are using Azure Container Apps and sending the data to an OpenTelemetry collector, which forwards the telemetry to Application Insights (we send it to more than one backend for high availability). What we observe in Application Insights is that cloud_RoleInstance shows the instance ID instead of the host_name.

Steps to Reproduce

Setup an Azure Container App and send the telemetry to the Opentelemetry collector.

Expected Result

See in the cloud_RoleInstance the value of the host name

Actual Result

In the cloud_RoleInstance, we see the value of the service instance id

Proposed solution

In the exporter/azuremonitorexporter/contracts_utils.go, change from:

func applyCloudTagsToEnvelope(envelope *contracts.Envelope, resourceAttributes pcommon.Map) {
	// Extract key service.* labels from the Resource labels and construct CloudRole and CloudRoleInstance envelope tags
	// https://github.com/open-telemetry/opentelemetry-specification/tree/main/specification/resource/semantic_conventions
	if serviceName, serviceNameExists := resourceAttributes.Get(string(conventions.ServiceNameKey)); serviceNameExists {
		cloudRole := serviceName.Str()

		if serviceNamespace, serviceNamespaceExists := resourceAttributes.Get(string(conventions.ServiceNamespaceKey)); serviceNamespaceExists {
			cloudRole = serviceNamespace.Str() + "." + cloudRole
		}

		envelope.Tags[contracts.CloudRole] = cloudRole
	}

	if serviceInstance, exists := resourceAttributes.Get(string(conventions.ServiceInstanceIDKey)); exists {
		envelope.Tags[contracts.CloudRoleInstance] = serviceInstance.Str()
	}

	envelope.Tags[contracts.InternalSdkVersion] = getCollectorVersion()
}

for

func applyCloudTagsToEnvelope(envelope *contracts.Envelope, resourceAttributes pcommon.Map) {
	// Extract key service.* labels from the Resource labels and construct CloudRole and CloudRoleInstance envelope tags
	// https://github.com/open-telemetry/opentelemetry-specification/tree/main/specification/resource/semantic_conventions
	if serviceName, serviceNameExists := resourceAttributes.Get(string(conventions.ServiceNameKey)); serviceNameExists {
		cloudRole := serviceName.Str()

		if serviceNamespace, serviceNamespaceExists := resourceAttributes.Get(string(conventions.ServiceNamespaceKey)); serviceNamespaceExists {
			cloudRole = serviceNamespace.Str() + "." + cloudRole
		}

		envelope.Tags[contracts.CloudRole] = cloudRole
	}

	if serviceInstance, exists := resourceAttributes.Get(string(conventions.HostNameKey)); exists {
		envelope.Tags[contracts.CloudRoleInstance] = serviceInstance.Str()
	}

	envelope.Tags[contracts.InternalSdkVersion] = getCollectorVersion()
}

Collector version

0.148.0

Environment information

Environment

Docker image 0.148.0

OpenTelemetry Collector configuration

receivers:
  otlp:
    protocols:
      grpc:
        endpoint: 0.0.0.0:4317
        auth:
          authenticator: bearertokenauth
      http:
        endpoint: 0.0.0.0:4318
        auth:
          authenticator: bearertokenauth

processors:
  batch:
  memory_limiter:
    check_interval: 5s
    limit_mib: 1536
    spike_limit_mib: 256

exporters:
  azuremonitor:
    connection_string: "${AIS_CONNECTION_STRING}"
    spaneventsenabled : true
    shutdown_timeout: 15s

extensions:
  health_check:
    endpoint: localhost:13133
  pprof:
    endpoint: localhost:1777
  zpages:
    endpoint: localhost:55679

service:
  extensions: [health_check, pprof, zpages]
  telemetry:
    logs:
      level: info
    metrics:
      readers:
        - pull:
            exporter:
              prometheus:
                host: localhost
                port: 8888
  pipelines:
    traces:
      receivers: [otlp]
      processors: [memory_limiter, batch]
      exporters: [azuremonitor]
    metrics:
      receivers: [otlp]
      processors: [memory_limiter, batch]
      exporters: [azuremonitor]
    logs:
      receivers: [otlp]
      processors: [memory_limiter, batch]
      exporters: [azuremonitor]

Log output

Additional context

No response

Tip

React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it. Learn more here.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions