envoyproxy/envoy

Opentelemetry stats sink does not populate the Resource attributes

Open

#39,931 opened on 2025年6月17日

GitHub で見る
 (7 comments) (0 reactions) (0 assignees)C++ (5,373 forks)batch import
area/opentelemetryenhancementhelp wanted

Repository metrics

Stars
 (27,997 stars)
PR merge metrics
 (平均マージ 8d) (30d で 378 merged PRs)

説明

Title: The stats reported via opentelemetry stats sink do not contain the resource details

Description: I am creating a custom processor in otel collector. This processor needs to determine which envoy proxy the metric report came from. I am trying to use the following code to get the Resource attributes which should ideally contain the nodes, cluster etc... but is empty. In summary the code is trying to access the MetricsData->Resourcemetrics->Resource->Attributes

func explorePMetricsStructure(metrics pmetric.Metrics) {
	// Top level: pmetric.Metrics
	fmt.Printf("Total ResourceMetrics: %d\n", metrics.ResourceMetrics().Len())

	// Level 1: ResourceMetrics - groups metrics by resource (e.g., service, host)
	for i := 0; i < metrics.ResourceMetrics().Len(); i++ {
		rm := metrics.ResourceMetrics().At(i)

		// Access resource attributes
		resource := rm.Resource()
		fmt.Printf("Resource attributes count: %d\n", resource.Attributes().Len())

		// Print some resource attributes
		resource.Attributes().Range(func(k string, v pcommon.Value) bool {  <------ nothing here
			fmt.Printf("  Resource attr: %s = %s\n", k, v.AsString())
			return true // continue iteration
		})

Repro steps: I used a custom otel processor for this, which might not be the best for repro. So here a some suggested repro steps

Admin and Stats Output: ``

Config:

admin:
  address:
    socket_address:
      address: 127.0.0.1
      port_value: 7777

node:
  cluster: test-cluster
  id: kraken
dynamic_resources:
  ads_config:
    api_type: DELTA_GRPC
    transport_api_version: V3
    grpc_services:
    - envoy_grpc:
        cluster_name: xds_cluster
    set_node_on_first_message_only: true
  cds_config:
    resource_api_version: V3
    ads: {}
  lds_config:
    resource_api_version: V3
    ads: {}
static_resources:
  clusters:
    - connect_timeout: 1s
      load_assignment:
        cluster_name: xds_cluster
        endpoints:
        - lb_endpoints:
          - endpoint:
              address:
                socket_address:
                  address: 127.0.0.1
                  port_value: 20240
      http2_protocol_options: {}
      name: xds_cluster

    - name: opentelemetry_collector
      type: STRICT_DNS
      lb_policy: ROUND_ROBIN
      http2_protocol_options: {}
      load_assignment:
        cluster_name: opentelemetry_collector
        endpoints:
          - lb_endpoints:
              - endpoint:
                  address:
                    socket_address:
                      address: 127.0.0.1
                      port_value: 20260


stats_sinks:
  - name: envoy.stat_sinks.open_telemetry
    typed_config:
      "@type": type.googleapis.com/envoy.extensions.stat_sinks.open_telemetry.v3.SinkConfig
      grpc_service:
        envoy_grpc:
          cluster_name: opentelemetry_collector
      emit_tags_as_attributes: true

overload_manager:
  resource_monitors:
    - name: "envoy.resource_monitors.global_downstream_max_connections"
      typed_config:
        "@type": type.googleapis.com/envoy.extensions.resource_monitors.downstream_connections.v3.DownstreamConnectionsConfig
        max_active_downstream_connections: 10000`

コントリビューターガイド