All Products
Search
Document Center

Managed Service for OpenTelemetry:OpenTelemetry integration guide

Last Updated:Apr 10, 2025

Managed Service for OpenTelemetry supports receiving trace, metric, and log data from applications, providing two reporting methods: direct reporting and forwarding via OpenTelemetry Collector.

Preparations

  • If you need to report log data, activate Simple Log Service (SLS), create a Project and a Logstore, and create an AccessKey pair in advance.

  • Refer to the variables, data types, and reporting methods listed in the following table to prepare the required endpoint and authentication information. For more information, see Prepare for using Managed Service for OpenTelemetry.

    Scenario

    Variable name

    Description

    Example

    Reporting trace and metric data

    Reporting via gRPC

    ${GRPC_ENDPOINT}

    The gRPC reporting endpoint of Managed Service for OpenTelemetry, which supports reporting trace and metric data.

    If your service is deployed in Alibaba Cloud and in the same region as Managed Service for OpenTelemetry, we recommend that you use an Alibaba Cloud internal network address. Otherwise, use a public network address.

    • Internal network address: http://tracing-analysis-dc-hz-internal.aliyuncs.com:8090

    • Public network address: http://tracing-analysis-dc-hz.aliyuncs.com:8090

    ${GRPC_AUTHENTICATION_TOKEN}

    The authentication token required when using gRPC to report data to Managed Service for OpenTelemetry. For information about how to obtain the token, see Prepare for using Managed Service for OpenTelemetry.

    abcdef1234@abcdef****56789_abcdef1234@abcdef****56789

    Reporting via HTTP

    ${HTTP_TRACES_ENDPOINT}

    The HTTP reporting endpoint of Managed Service for OpenTelemetry, which supports reporting trace data.

    If your service is deployed in Alibaba Cloud and in the same region as Managed Service for OpenTelemetry, we recommend that you use an Alibaba Cloud internal network address. Otherwise, use a public network address.

    • Internal network address: http://tracing-analysis-dc-hz-internal.aliyuncs.com/adapt_***_***/api/otlp/traces

    • Public network address: http://tracing-analysis-dc-hz.aliyuncs.com/adapt_***_***/api/otlp/traces

    ${HTTP_METRICS_ENDPOINT}

    The HTTP reporting endpoint of Managed Service for OpenTelemetry, which supports reporting metric data.

    If your service is deployed in Alibaba Cloud and in the same region as Managed Service for OpenTelemetry, we recommend that you use an Alibaba Cloud internal network address. Otherwise, use a public network address.

    • Internal network address: http://tracing-analysis-dc-hz-internal.aliyuncs.com/adapt_***_***/api/otlp/metrics

    • Public network address: http://tracing-analysis-dc-hz.aliyuncs.com/adapt_***_***/api/otlp/metrics

    Reporting log data

    ${SLS_ENDPOINT}

    The endpoint of the SLS project. This variable is required only when you report log data. For information about how to obtain the endpoint, see Endpoints.

    test-project.cn-hangzhou.log.aliyuncs.com

    ${SLS_PROJECT}

    The name of the SLS project. This variable is required only when you report log data.

    test-project

    ${SLS_LOGSTORE}

    The name of the SLS Logstore. This variable is required only when you report log data.

    test-logstore

    ${ALIYUN_ACCESS_KEY_ID}

    The AccessKey ID of your Alibaba Cloud account. This variable is required only when you report log data.

    We recommend that you use the AccessKey pair (including the ID and secret) of a RAM user who has only the write permissions on the SLS project. For information about how to grant a RAM user the permissions to write data to a specified project, see Examples of using custom policies to grant permissions to a RAM user. For information about how to obtain an AccessKey pair, see AccessKey pair.

    None

    ${ALIYUN_ACCESS_KEY_SECRET}

    The AccessKey secret of your Alibaba Cloud account. This variable is required only when you report log data.

    We recommend that you use the AccessKey pair (including the ID and secret) of a RAM user who has only the write permissions on the SLS project.

    None

Direct reporting

By configuring the reporting endpoint and authentication token of the OpenTelemetry agent or SDK, you can send the trace and metric data collected by OpenTelemetry directly to the Managed Service for OpenTelemetry server.

Method 1: Configure reporting settings in code

The following Java code examples show how to configure the endpoint information of Managed Service for OpenTelemetry to report data via HTTP and gRPC. Visit Integration Center or refer to Use OpenTelemetry to report the trace data of Java applications to view the complete code and demos.

Reporting via HTTP

... // Report trace data SdkTracerProvider sdkTracerProvider = SdkTracerProvider.builder() .addSpanProcessor(BatchSpanProcessor.builder(OtlpHttpSpanExporter.builder() .setEndpoint("${HTTP_TRACES_ENDPOINT}") // Set the HTTP endpoint to report trace data to Managed Service for OpenTelemetry. .build()).build()) .build(); // Report metric data SdkMeterProvider sdkMeterProvider = SdkMeterProvider.builder() .registerMetricReader(PeriodicMetricReader.builder(OtlpHttpMetricExporter.builder() .setEndpoint("${HTTP_METRICS_ENDPOINT}") // Set the HTTP endpoint to report metric data to Managed Service for OpenTelemetry. .build()).build()) .build(); ...

Reporting via gRPC

... // Report trace data SdkTracerProvider sdkTracerProvider = SdkTracerProvider.builder() .addSpanProcessor(BatchSpanProcessor.builder(OtlpGrpcSpanExporter.builder() .setEndpoint("${GRPC_AUTHENTICATION_TOKEN}") // Set the gRPC endpoint to report trace data to Managed Service for OpenTelemetry. .addHeader("Authentication","${GRPC_AUTHENTICATION_TOKEN}") // Set the authentication token for Managed Service for OpenTelemetry. .build()).build()) .setResource(resource) .build(); // Report metric data SdkMeterProvider sdkMeterProvider = SdkMeterProvider.builder() .registerMetricReader(PeriodicMetricReader.builder(OtlpGrpcMetricExporter.builder() .setEndpoint("${GRPC_METRICS_ENDPOINT}") // Set the gRPC endpoint to report trace data to Managed Service for OpenTelemetry. .addHeader("Authentication", "${GRPC_AUTHENTICATION_TOKEN}") // Set the authentication token for Managed Service for OpenTelemetry. .build()).build()) .setResource(resource) .build(); ...

Method 2: Configure reporting settings through environment variables

OpenTelemetry also supports configuring the reporting endpoint through environment variables, which are listed in the following table. For more OpenTelemetry Protocol environment variables, see OTLP Exporter Configuration.

Environment variable name

Description

Example

OTEL_SERVICE_NAME

The application name.

export OTEL_SERVICE_NAME=opentelemetry-demo-service

OTEL_EXPORTER_OTLP_PROTOCOL

The reporting protocol.

Trace reporting supports the following protocols: grpc, http/protobuf, and http/json.

Metric reporting supports the following protocols: grpc and http/protobuf.

When you select a gRPC reporting endpoint, set this variable to grpc. Otherwise, use http/protobuf or http/json.

export OTEL_EXPORTER_OTLP_PROTOCOL=grpc

OTEL_EXPORTER_OTLP_TRACES_ENDPOINT

The trace reporting endpoint. HTTP and gRPC endpoints are both supported.

The reporting endpoint is the value of ${GRPC_ENDPOINT} or ${HTTP_TRACES_ENDPOINT} obtained in Preparations.

  • Reporting via HTTP:

    export OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=http://tracing-analysis-dc-hz-internal.aliyuncs.com/adapt_***_***/api/otlp/traces

  • Reporting via gRPC:

    export OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=http://tracing-analysis-dc-hz-internal.aliyuncs.com:8090

OTEL_EXPORTER_OTLP_METRICS_ENDPOINT

The metric reporting endpoint. HTTP and gRPC endpoints are both supported.

The reporting endpoint is the value of ${GRPC_ENDPOINT} or ${HTTP_METRICS_ENDPOINT} obtained in Preparations.

  • Reporting via HTTP:

    export OTEL_EXPORTER_OTLP_METRICS_ENDPOINT=http://tracing-analysis-dc-hz-internal.aliyuncs.com/adapt_***_***/api/otlp/metrics

  • Reporting via gRPC:

    export OTEL_EXPORTER_OTLP_METRICS_ENDPOINT=http://tracing-analysis-dc-hz-internal.aliyuncs.com:8090

OTEL_EXPORTER_OTLP_HEADERS

The request header information for gRPC reporting, mainly used for authentication.

The format is Authentication=${GRPC_AUTHENTICATION_TOKEN}, where ${GRPC_AUTHENTICATION_TOKEN} is the authentication token obtained in Preparations.

export OTEL_EXPORTER_OTLP_HEADERS=Authentication=abcdef1234@abcdef****56789_abcdef1234@abcdef****56789

Forwarding via OpenTelemetry Collector

Background information

  • OpenTelemetry Collector (Core): supports reporting trace and metric data.

  • OpenTelemetry Collector (Contrib): supports reporting trace, metric, and log data.

Solution 1: Deploy OpenTelemetry Collector in the ACK cluster through ACK Marketplace

Important

ACK Marketplace currently only supports OpenTelemetry Collector (Core). If you need to collect logs, skip to Solution 2.

1. Deploy the Collector
  1. Log on to the ACK console. In the left-side navigation pane, choose Marketplace > Marketplace.

  2. On the Marketplace page, search for and click on opentelemetry-collector, and then click Deploy in the upper-right corner of the page that appears.

  3. In the Basic Information step, select the cluster and namespace (default: otel-collector) where you want to deploy opentelemetry-collector, and then click Next.

  4. In the Parameters step, set the mode parameter to deployment or daemonset, and then click OK.

2. Configure Collector parameters
  1. On the Clusters page of the ACK console, click on the ACK cluster.

  2. In the left-side navigation pane, choose Configurations > ConfigMaps.

  3. Select the namespace where opentelemetry-collector is located (default: otel-collector).

  4. On the ConfigMap page, find opentelemetry-collector, and then click Edit YAML in the Actions column.

  5. Refer to the following YAML file to configure the following sections: exporters, processors, receivers, and service, and then click OK.

    Opentelemetry-collector configuration (reporting via gRPC)

    exporters: otlp: endpoint: "${GRPC_ENDPOINT}" headers: Authentication: "${GRPC_AUTHENTICATION_TOKEN}" tls: insecure: true processors: batch: {} memory_limiter: check_interval: 5s # The interval to check memory usage. Adjust it as needed. limit_percentage: 80 # The maximum percentage of memory usage. Adjust it as needed. spike_limit_percentage: 25 # The additional percentage of memory allowed for spikes. Adjust it as needed. receivers: otlp: protocols: grpc: endpoint: ${env:MY_POD_IP}:4317 http: endpoint: ${env:MY_POD_IP}:4318 service: pipelines: traces: exporters: [otlp] processors: [memory_limiter, batch] receivers: [otlp] metrics: exporters: [otlp] processors: [memory_limiter, batch] receivers: [otlp]

    Opentelemetry-collector configuration (reporting via HTTP)

    exporters: otlphttp: traces_endpoint: "${HTTP_TRACES_ENDPOINT}" metrics_endpoint: "${HTTP_METRICS_ENDPOINT}" tls: insecure: true timeout: 5s # The timeout duration. Default value: 5s. Adjust it as needed. processors: batch: {} memory_limiter: check_interval: 5s # The interval to check memory usage. Adjust it as needed. limit_percentage: 80 # The maximum percentage of memory usage. Adjust it as needed. spike_limit_percentage: 25 # The additional percentage of memory allowed for spikes. Adjust it as needed. receivers: otlp: protocols: grpc: endpoint: ${env:MY_POD_IP}:4317 http: endpoint: ${env:MY_POD_IP}:4318 service: pipelines: traces: exporters: [otlphttp] processors: [memory_limiter, batch] receivers: [otlp] metrics: exporters: [otlphttp] processors: [memory_limiter, batch] receivers: [otlp]
  6. After the configuration is complete, manually restart opentelemetry-collector.

Solution 2: Deploy OpenTelemetry Collector using Docker

1. Pull the image

OpenTelemetry Collector (Core)

To specify an image version, visit https://hub.docker.com/r/otel/opentelemetry-collector/tags.

docker pull otel/opentelemetry-collector:latest

OpenTelemetry Collector (Contrib)

To specify an image version, visit https://hub.docker.com/r/otel/opentelemetry-collector-contrib/tags.

docker pull otel/opentelemetry-collector-contrib:latest
2. Prepare a configuration file

Create a config.yaml file and configure the relevant parameters.

OpenTelemetry Collector (Core) configuration (reporting via gRPC)

# config.yaml exporters: otlp: endpoint: "${GRPC_ENDPOINT}" headers: Authentication: "${GRPC_AUTHENTICATION_TOKEN}" tls: insecure: true processors: batch: {} memory_limiter: check_interval: 5s # The interval to check memory usage. Adjust it as needed. limit_percentage: 80 # The maximum percentage of memory usage. Adjust it as needed. spike_limit_percentage: 25 # The additional percentage of memory allowed for spikes. Adjust it as needed. receivers: otlp: protocols: grpc: endpoint: 0.0.0.0:4317 # Default value is localhost:4317. Adjust it as needed. http: endpoint: 0.0.0.0:4318 # Default value is localhost:4318. Adjust it as needed. service: pipelines: traces: exporters: [otlp] processors: [memory_limiter, batch] receivers: [otlp] metrics: exporters: [otlp] processors: [memory_limiter, batch] receivers: [otlp]

OpenTelemetry Collector (Core) configuration (reporting via HTTP)

# config.yaml exporters: otlphttp: traces_endpoint: "${HTTP_TRACES_ENDPOINT}" metrics_endpoint: "${HTTP_METRICS_ENDPOINT}" tls: insecure: true timeout: 5s # The timeout duration. Default value: 5s. Adjust it as needed. processors: batch: {} memory_limiter: check_interval: 5s # The interval to check memory usage. Adjust it as needed. limit_percentage: 80 # The maximum percentage of memory usage. Adjust it as needed. spike_limit_percentage: 25 # The additional percentage of memory allowed for spikes. Adjust it as needed. receivers: otlp: protocols: grpc: endpoint: 0.0.0.0:4317 # Default value is localhost:4317. Adjust it as needed. http: endpoint: 0.0.0.0:4318 # Default value is localhost:4318. Adjust it as needed. service: pipelines: traces: exporters: [otlphttp] processors: [memory_limiter, batch] receivers: [otlp] metrics: exporters: [otlphttp] processors: [memory_limiter, batch] receivers: [otlp]

OpenTelemetry Collector (Contrib) configuration (reporting via gRPC)

# config.yaml exporters: otlp: endpoint: "${GRPC_ENDPOINT}" headers: Authentication: "${GRPC_AUTHENTICATION_TOKEN}" tls: insecure: true # Log exporter configuration (optional) alibabacloud_logservice/logs: endpoint: "${SLS_ENDPOINT}" project: "${SLS_PROJECT}" logstore: "${SLS_LOGSTORE}" access_key_id: "${ALIYUN_ACCESS_KEY_ID}" access_key_secret: "${ALIYUN_ACCESS_KEY_SECRET}" processors: batch: {} memory_limiter: check_interval: 5s # The interval to check memory usage. Adjust it as needed. limit_percentage: 80 # The maximum percentage of memory usage. Adjust it as needed. spike_limit_percentage: 25 # The additional percentage of memory allowed for spikes. Adjust it as needed. receivers: otlp: protocols: grpc: endpoint: 0.0.0.0:4317 # Default value is localhost:4317. Adjust it as needed. http: endpoint: 0.0.0.0:4318 # Default value is localhost:4318. Adjust it as needed. service: pipelines: traces: exporters: [otlp] processors: [memory_limiter, batch] receivers: [otlp] metrics: exporters: [otlp] processors: [memory_limiter, batch] receivers: [otlp] # Log data processing flow (optional) logs: exporters: [alibabacloud_logservice/logs] processors: [memory_limiter, batch] receivers: [otlp]

OpenTelemetry Collector (Contrib) configuration (reporting via HTTP)

# config.yaml exporters: otlphttp: traces_endpoint: "${HTTP_TRACES_ENDPOINT}" metrics_endpoint: "${HTTP_METRICS_ENDPOINT}" tls: insecure: true timeout: 5s # The timeout duration. Default value: 5s. Adjust it as needed. # Log exporter configuration (optional) alibabacloud_logservice/logs: endpoint: "${SLS_ENDPOINT}" project: "${SLS_PROJECT}" logstore: "${SLS_LOGSTORE}" access_key_id: "${ALIYUN_ACCESS_KEY_ID}" access_key_secret: "${ALIYUN_ACCESS_KEY_SECRET}" processors: batch: {} memory_limiter: check_interval: 5s # The interval to check memory usage. Adjust it as needed. limit_percentage: 80 # The maximum percentage of memory usage. Adjust it as needed. spike_limit_percentage: 25 # The additional percentage of memory allowed for spikes. Adjust it as needed. receivers: otlp: protocols: grpc: endpoint: 0.0.0.0:4317 # Default value is localhost:4317. Adjust it as needed. http: endpoint: 0.0.0.0:4318 # Default value is localhost:4318. Adjust it as needed. service: pipelines: traces: exporters: [otlphttp] processors: [memory_limiter, batch] receivers: [otlp] metrics: exporters: [otlphttp] processors: [memory_limiter, batch] receivers: [otlp] # Log data processing flow (optional) logs: exporters: [alibabacloud_logservice/logs] processors: [memory_limiter, batch] receivers: [otlp]
3. Mount and run the configuration file

OpenTelemetry Collector (Core)

docker run -v $(pwd)/config.yaml:/etc/otelcol/config.yaml otel/opentelemetry-collector:latest

OpenTelemetry Collector (Contrib)

docker run -v $(pwd)/config.yaml:/etc/otelcol-contrib/config.yaml otel/opentelemetry-collector-contrib:latest

Other solutions

References