### HTTP Receiver Configuration Example Source: https://github.com/open-telemetry/opentelemetry-collector/blob/main/config/confighttp/README.md Example configuration for the OTLP HTTP receiver, demonstrating metadata inclusion, authentication, CORS settings, endpoint, and compression algorithms. It also shows an example of an attribute processor to capture client IP. ```yaml receivers: otlp: protocols: http: include_metadata: true auth: request_params: - token authenticator: some-authenticator-extension cors: allowed_origins: - https://foo.bar.com - https://*.test.com allowed_headers: - Example-Header exposed_headers: - Example-Expose-Header max_age: 7200 endpoint: 0.0.0.0:55690 compression_algorithms: ["", "gzip"] processors: attributes: actions: - key: http.client_ip from_context: metadata.x-forwarded-for action: upsert ``` -------------------------------- ### HTTP Exporter Configuration Example Source: https://github.com/open-telemetry/opentelemetry-collector/blob/main/config/confighttp/README.md Example configuration for an OTLP HTTP exporter, demonstrating endpoint, authentication, TLS, custom headers, and compression settings. ```yaml exporter: otlp_http: endpoint: otelcol2:55690 auth: authenticator: some-authenticator-extension tls: ca_file: ca.pem cert_file: cert.pem key_file: key.pem headers: test1: "value1" "test 2": "value 2" compression: gzip compression_params: level: 1 cookies: enabled: true ``` -------------------------------- ### Example .schemagen.yaml Configuration Source: https://github.com/open-telemetry/opentelemetry-collector/blob/main/cmd/schemagen/README.md This snippet shows a typical configuration for the .schemagen.yaml file, demonstrating namespace, mappings, allowedRefs, and componentOverrides. ```yaml namespace: github.com/open-telemetry/opentelemetry-collector-contrib mappings: time: Duration: schemaType: string format: duration allowedRefs: - go.opentelemetry.io/collector - github.com/open-telemetry/opentelemetry-collector-contrib componentOverrides: receiver/named_pipe: configName: 'NamedPipeConfig' receiver/file_log: configName: 'FileLogConfig' receiver/prometheus: overlayFile: receiver/prometheusreceiver/config.schema.overlay.yaml ``` -------------------------------- ### Install OCB via Go Install Source: https://github.com/open-telemetry/opentelemetry-collector/blob/main/cmd/builder/README.md Installs the latest version of the OpenTelemetry Collector Builder using `go install`. The binary will be named `builder` and requires a compatible Go compiler in the PATH. ```console go install go.opentelemetry.io/collector/cmd/builder@latest ``` -------------------------------- ### Example Main Configuration Source: https://github.com/open-telemetry/opentelemetry-collector/blob/main/confmap/README.md This is the primary configuration file for the OpenTelemetry Collector, defining receivers, processors, exporters, and extensions. ```yaml # main.yaml receivers: otlp/in: processors: attributes/example: actions: - key: key value: "value" action: upsert exporters: otlp/out: extensions: file_storage: service: pipelines: traces: receivers: [ otlp/in ] processors: [ attributes/example ] exporters: [ otlp/out ] extensions: [ file_storage ] ``` -------------------------------- ### Example of Verifying Collector Image Signature Source: https://github.com/open-telemetry/opentelemetry-collector/blob/main/README.md An example command demonstrating how to verify the signature for a specific release tag and image of the OpenTelemetry Collector. ```console $ cosign verify --certificate-identity=https://github.com/open-telemetry/opentelemetry-collector-releases/.github/workflows/base-release.yaml@refs/tags/v0.98.0 --certificate-oidc-issuer=https://token.actions.githubusercontent.com ghcr.io/open-telemetry/opentelemetry-collector-releases/opentelemetry-collector-contrib:0.98.0 ``` -------------------------------- ### Example Metric Reaggregation Configuration Source: https://github.com/open-telemetry/opentelemetry-collector/blob/main/cmd/mdatagen/README.md Example showing how to configure aggregation strategy and attributes for a specific metric. This aggregates datapoints by status_code while keeping transport. ```yaml receivers: myreceiver: metrics: http.server.request.count: enabled: true aggregation_strategy: sum attributes: [transport] ``` -------------------------------- ### Configure Example Exporters Source: https://github.com/open-telemetry/opentelemetry-collector/blob/main/exporter/README.md Configure two instances of an example exporter with different endpoints. Exporter names are used to reference them in pipelines. ```yaml exporters: # Exporter 1. # : exampleexporter: # : endpoint: 1.2.3.4:8080 # ... # Exporter 2. # /: exampleexporter/settings: # : endpoint: 0.0.0.0:9211 ``` -------------------------------- ### Build Custom Collector with OCB Source: https://github.com/open-telemetry/opentelemetry-collector/blob/main/cmd/builder/README.md Installs the builder, defines a configuration file specifying components and output paths, builds the collector, and then runs the custom collector with its own configuration. ```console $ go install go.opentelemetry.io/collector/cmd/builder@v0.129.0 $ cat > otelcol-builder.yaml < /tmp/otelcol.yaml <Func for CreateTraces type CreateTracesFunc func(context.Context, Settings, component.Config, consumer.Traces) (Traces, error) // Functional option for traces capability func WithTraces(createTraces CreateTracesFunc, sl component.StabilityLevel) FactoryOption { ... } // Constructor uses functional options func NewFactory(cfgType component.Type, createDefaultConfig component.CreateDefaultConfigFunc, options ...FactoryOption) Factory ``` -------------------------------- ### Fork Trace Pipelines with Forward Connector Source: https://github.com/open-telemetry/opentelemetry-collector/blob/main/connector/forwardconnector/README.md This example shows how to fork a single trace pipeline into two distinct paths: 'traces/hot' and 'traces/cold'. Data from the initial 'traces' pipeline is sent to the 'forward' connector, which then directs it to two separate pipelines, each with its own processor and exporter. ```yaml receivers: foo: processors: resourcedetection: sample: attributes: exporters: bar/hot: bar/cold: connectors: forward: service: pipelines: traces: receivers: [foo] processors: [resourcedetection] exporters: [forward] traces/hot: receivers: [forward] processors: [sample] exporters: [bar/hot] traces/cold: receivers: [forward] processors: [attributes] exporters: [bar/cold] ``` -------------------------------- ### Reduce Attribute Cardinality Source: https://github.com/open-telemetry/opentelemetry-collector/blob/main/docs/rfcs/processing.md Normalize attribute values to reduce cardinality, for example, by replacing specific user IDs with a placeholder. ```yaml traces: replace_match(attributes["http.target"], "/user/*/list/*", "/user/{userId}/list/{listId}") ``` -------------------------------- ### Deprecated Function Godoc Example Source: https://github.com/open-telemetry/opentelemetry-collector/blob/main/docs/coding-guidelines.md Illustrates how to mark a Go function as deprecated with a version and alternative. Use this for tracking deprecation. ```golang package test // Deprecated: [v0.45.0] Use MustDoFoo instead. func DoFoo() {} ``` -------------------------------- ### Debugging with Delve Source: https://github.com/open-telemetry/opentelemetry-collector/blob/main/cmd/builder/README.md Install Delve and run the OpenTelemetry Collector with dlv for debugging. Ensure debugging symbols are preserved and optimizations are disabled. ```bash # go install github.com/go-delve/delve/cmd/dlv@latest # ~/go/bin/dlv --listen=:2345 --headless=true --api-version=2 --accept-multiclient --log exec .otel-collector-binary -- --config otel-collector-config.yaml ``` -------------------------------- ### go:generate directive for mdatagen Source: https://github.com/open-telemetry/opentelemetry-collector/blob/main/cmd/mdatagen/README.md A `doc.go` file example showing the `go:generate mdatagen` directive to trigger metadata generation. ```go //go:generate mdatagen metadata.yaml package main ``` -------------------------------- ### Pull Official OCB Docker Image Source: https://github.com/open-telemetry/opentelemetry-collector/blob/main/cmd/builder/README.md Pulls the latest Docker image for the OpenTelemetry Collector Builder from DockerHub. This is the recommended installation method. ```console docker pull otel/opentelemetry-collector-builder:latest ```