If you use the OpenTelemetry SDK to collect trace data, you can send the trace data to Tracing Analysis, or forward the trace data to Tracing Analysis by using the OpenTelemetry Collector.
Prerequisites
Obtain an authentication token in the Tracing Analysis console. For more information, see Obtain an authentication token.Directly submit data
If you use the OpenTelemetry SDK to collect the trace data of an application, you can send the trace data to Tracing Analysis over OpenTelemetry gRPC. To do this, you must specify an endpoint and the required authentication token.
- Endpoint: Replace <endpoint> with the endpoint that you obtained in the "Prerequisites" section.
- Authentication token: Add the authentication token that you obtained in the "Prerequisites" section to the header of a gRPC request.
Sample code in Java:
SdkTracerProvider sdkTracerProvider = SdkTracerProvider.builder()
.addSpanProcessor(BatchSpanProcessor.builder(OtlpGrpcSpanExporter.builder()
.setEndpoint("<endpoint>")
.addHeader("Authentication", "<token>")
.build()).build())
.build();
- Replace
<endpoint>
with the endpoint that you obtained in the "Prerequisites" section. Example:http://tracing-analysis-dc-bj.aliyuncs.com:8090
. - Replace
<token>
with the token that you obtained in the "Prerequisites" section. Example:b590lhguqs@3a7xxxxxxx9b_b590lhguqs@53dxxxxx8301
.
Use the OpenTelemetry Collector to forward trace data
If you use the OpenTelemetry SDK or the OpenTelemetry Collector to collect the trace data of an application, you must set the Endpoint parameter to the URL of the OpenTelemetry Collector that is deployed on an on-premises host. In this case, you do not need to specify authentication information. However, you must configure an OLTP exporter in the OpenTelemetry Collector. The OLTP exporter contains an endpoint and authentication information. You can use the OLTP exporter to submit trace data to Tracing Analysis.
Install the OpenTelemetry Collector
To install the OpenTelemetry Collector, you can download and run the installation package of the OpenTelemetry Collector in the binary format, or use Docker to install and run the OpenTelemetry image.
- Download URL of the installation package of the OpenTelemetry Collector in the binary format: OpenTelemetry Collector.
- To use Docker to install the OpenTelemetry image, run the following command:
docker pull otel/opentelemetry-collector:0.66.0
Configure the OpenTelemetry Collector.
To use the OpenTelemetry Collector to forward trace data, you can make gRPC requests or HTTP requests. Both types of requests require different configuration files.
- Create a configuration file to make a gRPC requestThe following code describes how to create a gRPC configuration file otel-config.yaml. Modify the configuration file based on your needs.Note Modify the exports section in the configuration file:
- Replace
<endpoint>
with the endpoint that you obtained in the "Prerequisites" section. Example:http://tracing-analysis-dc-bj.aliyuncs.com:8090
. - Replace
<token>
with the token that you obtained in the "Prerequisites" section. Example:b590lhguqs@3a7xxxxxxx9b_b590lhguqs@53dxxxxx8301
.
extensions: memory_ballast: size_mib: 512 zpages: endpoint: 0.0.0.0:55679 receivers: otlp: protocols: grpc: http: processors: batch: memory_limiter: # 75% of maximum memory up to 4G limit_mib: 1536 # 25% of limit up to 2G spike_limit_mib: 512 check_interval: 5s exporters: logging: logLevel: debug otlp: endpoint: <endpoint>:8090 tls: insecure: true headers: Authentication: <token> service: pipelines: traces: receivers: [otlp] processors: [memory_limiter, batch] exporters: [logging, otlp] metrics: receivers: [otlp] processors: [memory_limiter, batch] exporters: [logging] extensions: [memory_ballast, zpages]
- Replace
- Create a configuration file to make an HTTP requestThe following code describes how to create an HTTP configuration file otel-config.yaml. Modify the configuration file based on your needs.Note Replace
<traces_endpoint>
with the endpoint that you obtained in the "Prerequisites" section. Example:http://tracing-analysis-dc-hz.aliyuncs.com/adapt_XXXXX/api/otlp/traces
.extensions: memory_ballast: size_mib: 512 zpages: endpoint: 0.0.0.0:55679 receivers: otlp: protocols: grpc: http: processors: batch: memory_limiter: # 75% of maximum memory up to 4G limit_mib: 1536 # 25% of limit up to 2G spike_limit_mib: 512 check_interval: 5s exporters: logging: logLevel: debug otlphttp: traces_endpoint: http://tracing-analysis-dc-hz.aliyuncs.com/adapt_XXXXX/api/otlp/traces tls: insecure: true timeout: 120s service: pipelines: traces: receivers: [otlp] processors: [memory_limiter, batch] exporters: [logging, otlphttp] metrics: receivers: [otlp] processors: [memory_limiter, batch] exporters: [logging] extensions: [memory_ballast, zpages]
Start the OpenTelemetry Collector.
- If you download and run the installation package of the OpenTelemetry Collector in the binary format, run the following command to start the OpenTelemetry Collector:
./ocb_0.44.0_linux_amd64 --config="./otel-config.yaml"
- If you use Docker to install and run the OpenTelemetry image, run the following command to start the OpenTelemetry Collector:
docker run -v $(pwd)/otel-config.yaml:/etc/otelcol/config.yaml otel/opentelemetry-collector:0.66.0