# opentelemetry-operator **Repository Path**: kanghuatao/opentelemetry-operator ## Basic Information - **Project Name**: opentelemetry-operator - **Description**: No description available - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-01-26 - **Last Updated**: 2024-01-26 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README [![Continuous Integration][github-workflow-img]][github-workflow] [![Go Report Card][goreport-img]][goreport] [![GoDoc][godoc-img]][godoc] # OpenTelemetry Operator for Kubernetes The OpenTelemetry Operator is an implementation of a [Kubernetes Operator](https://kubernetes.io/docs/concepts/extend-kubernetes/operator/). The operator manages: * [OpenTelemetry Collector](https://github.com/open-telemetry/opentelemetry-collector) * [auto-instrumentation](https://opentelemetry.io/docs/concepts/instrumentation/automatic/) of the workloads using OpenTelemetry instrumentation libraries ## Documentation * [API docs](./docs/api.md) ## Helm Charts You can install Opentelemetry Operator via [Helm Chart](https://github.com/open-telemetry/opentelemetry-helm-charts/tree/main/charts/opentelemetry-operator) from the opentelemetry-helm-charts repository. More information is available in [here](https://github.com/open-telemetry/opentelemetry-helm-charts/tree/main/charts/opentelemetry-operator). ## Getting started To install the operator in an existing cluster, make sure you have [`cert-manager` installed](https://cert-manager.io/docs/installation/) and run: ```bash kubectl apply -f https://github.com/open-telemetry/opentelemetry-operator/releases/latest/download/opentelemetry-operator.yaml ``` Once the `opentelemetry-operator` deployment is ready, create an OpenTelemetry Collector (otelcol) instance, like: ```yaml kubectl apply -f - < 🚨 **NOTE:** At this point, the Operator does *not* validate the contents of the configuration file: if the configuration is invalid, the instance will still be created but the underlying OpenTelemetry Collector might crash. The Operator does examine the configuration file to discover configured receivers and their ports. If it finds receivers with ports, it creates a pair of kubernetes services, one headless, exposing those ports within the cluster. The headless service contains a `service.beta.openshift.io/serving-cert-secret-name` annotation that will cause OpenShift to create a secret containing a certificate and key. This secret can be mounted as a volume and the certificate and key used in those receivers' TLS configurations. ### Upgrades As noted above, the OpenTelemetry Collector format is continuing to evolve. However, a best-effort attempt is made to upgrade all managed `OpenTelemetryCollector` resources. In certain scenarios, it may be desirable to prevent the operator from upgrading certain `OpenTelemetryCollector` resources. For example, when a resource is configured with a custom `.Spec.Image`, end users may wish to manage configuration themselves as opposed to having the operator upgrade it. This can be configured on a resource by resource basis with the exposed property `.Spec.UpgradeStrategy`. By configuring a resource's `.Spec.UpgradeStrategy` to `none`, the operator will skip the given instance during the upgrade routine. The default and only other acceptable value for `.Spec.UpgradeStrategy` is `automatic`. ### Deployment modes The `CustomResource` for the `OpenTelemetryCollector` exposes a property named `.Spec.Mode`, which can be used to specify whether the Collector should run as a [`DaemonSet`](https://kubernetes.io/docs/concepts/workloads/controllers/daemonset/), [`Sidecar`](https://kubernetes.io/docs/concepts/workloads/pods/#workload-resources-for-managing-pods), [`StatefulSet`](https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/) or [`Deployment`](https://kubernetes.io/docs/concepts/workloads/controllers/deployment/) (default). See below for examples of each deployment mode: - [`Deployment`](https://github.com/open-telemetry/opentelemetry-operator/blob/main/tests/e2e/ingress/00-install.yaml) - [`DaemonSet`](https://github.com/open-telemetry/opentelemetry-operator/blob/main/tests/e2e/daemonset-features/01-install.yaml) - [`StatefulSet`](https://github.com/open-telemetry/opentelemetry-operator/blob/main/tests/e2e/smoke-statefulset/00-install.yaml) - [`Sidecar`](https://github.com/open-telemetry/opentelemetry-operator/blob/main/tests/e2e/smoke-sidecar/00-install.yaml) #### Sidecar injection A sidecar with the OpenTelemetry Collector can be injected into pod-based workloads by setting the pod annotation `sidecar.opentelemetry.io/inject` to either `"true"`, or to the name of a concrete `OpenTelemetryCollector`, like in the following example: ```yaml kubectl apply -f - < 🚨 **NOTE**: Go auto-instrumentation **does not** support multicontainer pods. When injecting Go auto-instrumentation the first pod should be the only pod you want instrumented. #### Multi-container pods with multiple instrumentations Works only when `operator.autoinstrumentation.multi-instrumentation` feature is `enabled`. Annotations defining which language instrumentation will be injected are required. When feature is enabled, specific for Instrumentation language containers annotations are used: Java: ```bash instrumentation.opentelemetry.io/java-container-names: "java1,java2" ``` NodeJS: ```bash instrumentation.opentelemetry.io/nodejs-container-names: "nodejs1,nodejs2" ``` Python: ```bash instrumentation.opentelemetry.io/python-container-names: "python1,python3" ``` DotNet: ```bash instrumentation.opentelemetry.io/dotnet-container-names: "dotnet1,dotnet2" ``` Go: ```bash instrumentation.opentelemetry.io/go-container-names: "go1" ``` ApacheHttpD: ```bash instrumentation.opentelemetry.io/apache-httpd-container-names: "apache1,apache2" ``` SDK: ```bash instrumentation.opentelemetry.io/sdk-container-names: "app1,app2" ``` If language instrumentation specific container names are not specified, instrumentation is performed on the first container available in the pod spec (only if single instrumentation injection is configured). In some cases containers in the pod are using different technologies. It becomes necessary to specify language instrumentation for container(s) on which this injection must be performed. For this, we will use language instrumentation specific container names annotation for which we will indicate one or more container names (`.spec.containers.name`) on which the injection must be made: ```yaml apiVersion: apps/v1 kind: Deployment metadata: name: my-deployment-with-multi-containers-multi-instrumentations spec: selector: matchLabels: app: my-pod-with-multi-containers-multi-instrumentations replicas: 1 template: metadata: labels: app: my-pod-with-multi-containers-multi-instrumentations annotations: instrumentation.opentelemetry.io/inject-java: "true" instrumentation.opentelemetry.io/java-container-names: "myapp,myapp2" instrumentation.opentelemetry.io/inject-python: "true" instrumentation.opentelemetry.io/python-container-names: "myapp3" spec: containers: - name: myapp image: myImage1 - name: myapp2 image: myImage2 - name: myapp3 image: myImage3 ``` In the above case, `myapp` and `myapp2` containers will be instrumented using Java and `myapp3` using Python instrumentation. **NOTE**: Go auto-instrumentation **does not** support multicontainer pods. When injecting Go auto-instrumentation the first container should be the only you want to instrument. **NOTE**: This type of instrumentation **does not** allow to instrument a container with multiple language instrumentations. **NOTE**: `instrumentation.opentelemetry.io/container-names` annotation is not used for this feature. #### Use customized or vendor instrumentation By default, the operator uses upstream auto-instrumentation libraries. Custom auto-instrumentation can be configured by overriding the `image` fields in a CR. ```yaml apiVersion: opentelemetry.io/v1alpha1 kind: Instrumentation metadata: name: my-instrumentation spec: java: image: your-customized-auto-instrumentation-image:java nodejs: image: your-customized-auto-instrumentation-image:nodejs python: image: your-customized-auto-instrumentation-image:python dotnet: image: your-customized-auto-instrumentation-image:dotnet go: image: your-customized-auto-instrumentation-image:go apacheHttpd: image: your-customized-auto-instrumentation-image:apache-httpd nginx: image: your-customized-auto-instrumentation-image:nginx ``` The Dockerfiles for auto-instrumentation can be found in [autoinstrumentation directory](./autoinstrumentation). Follow the instructions in the Dockerfiles on how to build a custom container image. #### Using Apache HTTPD autoinstrumentation For `Apache HTTPD` autoinstrumentation, by default, instrumentation assumes httpd version 2.4 and httpd configuration directory `/usr/local/apache2/conf` as it is in the official `Apache HTTPD` image (f.e. docker.io/httpd:latest). If you need to use version 2.2, or your HTTPD configuration directory is different, and or you need to adjust agent attributes, customize the instrumentation specification per following example: ```yaml apiVersion: opentelemetry.io/v1alpha1 kind: Instrumentation metadata: name: my-instrumentation apache: image: your-customized-auto-instrumentation-image:apache-httpd version: 2.2 configPath: /your-custom-config-path attrs: - name: ApacheModuleOtelMaxQueueSize value: "4096" - name: ... value: ... ``` List of all available attributes can be found at [otel-webserver-module](https://github.com/open-telemetry/opentelemetry-cpp-contrib/tree/main/instrumentation/otel-webserver-module) #### Using Nginx autoinstrumentation For `Nginx` autoinstrumentation, Nginx versions 1.22.0, 1.23.0, and 1.23.1 are supported at this time. The Nginx configuration file is expected to be `/etc/nginx/nginx.conf` by default, if it's different, see following example on how to change it. Instrumentation at this time also expects, that `conf.d` directory is present in the directory, where configuration file resides and that there is a `include /conf.d/*.conf;` directive in the `http { ... }` section of Nginx configuration file (like it is in the default configuration file of Nginx). You can also adjust OpenTelemetry SDK attributes. Example: ```yaml apiVersion: opentelemetry.io/v1alpha1 kind: Instrumentation metadata: name: my-instrumentation nginx: image: your-customized-auto-instrumentation-image:nginx # if custom instrumentation image is needed configFile: /my/custom-dir/custom-nginx.conf attrs: - name: NginxModuleOtelMaxQueueSize value: "4096" - name: ... value: ... ``` List of all available attributes can be found at [otel-webserver-module](https://github.com/open-telemetry/opentelemetry-cpp-contrib/tree/main/instrumentation/otel-webserver-module) #### Inject OpenTelemetry SDK environment variables only You can configure the OpenTelemetry SDK for applications which can't currently be autoinstrumented by using `inject-sdk` in place of `inject-python` or `inject-java`, for example. This will inject environment variables like `OTEL_RESOURCE_ATTRIBUTES`, `OTEL_TRACES_SAMPLER`, and `OTEL_EXPORTER_OTLP_ENDPOINT`, that you can configure in the `Instrumentation`, but will not actually provide the SDK. ```bash instrumentation.opentelemetry.io/inject-sdk: "true" ``` #### Controlling Instrumentation Capabilities The operator allows specifying, via the feature gates, which languages the Instrumentation resource may instrument. These feature gates must be passed to the operator via the `--feature-gates` flag. The flag allows for a comma-delimited list of feature gate identifiers. Prefix a gate with '-' to disable support for the corresponding language or multi instrumentation feature. Prefixing a gate with '+' or no prefix will enable support for the corresponding language or multi instrumentation feature. If a language is enabled by default its gate only needs to be supplied when disabling the gate. | Language | Gate | Default Value | |---------------|---------------------------------------------|---------------| | Java | `operator.autoinstrumentation.java` | enabled | | NodeJS | `operator.autoinstrumentation.nodejs` | enabled | | Python | `operator.autoinstrumentation.python` | enabled | | DotNet | `operator.autoinstrumentation.dotnet` | enabled | | ApacheHttpD | `operator.autoinstrumentation.apache-httpd` | enabled | | Go | `operator.autoinstrumentation.go` | disabled | | Nginx | `operator.autoinstrumentation.nginx` | disabled | Language not specified in the table are always supported and cannot be disabled. OpenTelemetry Operator allows to instrument multiple containers using multiple language specific instrumentations. These features can be enabled using `operator.autoinstrumentation.multi-instrumentation` flag when installing the Operator via Helm. By default flag is `disabled`. For example: ```sh helm install opentelemetry-operator open-telemetry/opentelemetry-operator --set manager.featureGates=operator.autoinstrumentation.multi-instrumentation ``` For more information about multi-instrumentation feature capabilities please see [Multi-container pods with multiple instrumentations](#Multi-container-pods-with-multiple-instrumentations). ### Target Allocator The OpenTelemetry Operator comes with an optional component, the [Target Allocator](/cmd/otel-allocator/README.md) (TA). When creating an OpenTelemetryCollector Custom Resource (CR) and setting the TA as enabled, the Operator will create a new deployment and service to serve specific `http_sd_config` directives for each Collector pod as part of that CR. It will also rewrite the Prometheus receiver configuration in the CR, so that it uses the deployed target allocator. The following example shows how to get started with the Target Allocator: ```yaml apiVersion: opentelemetry.io/v1alpha1 kind: OpenTelemetryCollector metadata: name: collector-with-ta spec: mode: statefulset targetAllocator: enabled: true config: | receivers: prometheus: config: scrape_configs: - job_name: 'otel-collector' scrape_interval: 10s static_configs: - targets: [ '0.0.0.0:8888' ] metric_relabel_configs: - action: labeldrop regex: (id|name) replacement: $$1 - action: labelmap regex: label_(.+) replacement: $$1 exporters: debug: service: pipelines: metrics: receivers: [prometheus] processors: [] exporters: [debug] ``` The usage of `$$` in the replacement keys in the example above is based on the information provided in the Prometheus receiver [README](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/receiver/prometheusreceiver/README.md) documentation, which states: `Note: Since the collector configuration supports env variable substitution $ characters in your prometheus configuration are interpreted as environment variables. If you want to use $ characters in your prometheus configuration, you must escape them using $$.` Behind the scenes, the OpenTelemetry Operator will convert the Collector’s configuration after the reconciliation into the following: ```yaml receivers: prometheus: target_allocator: endpoint: http://collector-with-ta-targetallocator:80 interval: 30s collector_id: $POD_NAME exporters: debug: service: pipelines: metrics: receivers: [prometheus] processors: [] exporters: [debug] ``` The OpenTelemetry Operator will also convert the Target Allocator's Prometheus configuration after the reconciliation into the following: ```yaml config: scrape_configs: - job_name: otel-collector scrape_interval: 10s static_configs: - targets: [ '0.0.0.0:8888' ] metric_relabel_configs: - action: labeldrop regex: (id|name) replacement: $1 - action: labelmap regex: label_(.+) replacement: $1 ``` Note that in this case, the Operator replaces "$$" with a single "$" in the replacement keys. This is because the collector supports environment variable substitution, whereas the TA (Target Allocator) does not. Therefore, to ensure compatibility, the TA configuration should only contain a single "$" symbol. More info on the TargetAllocator can be found [here](cmd/otel-allocator/README.md). #### Using Prometheus Custom Resources for service discovery The target allocator can use Custom Resources from the prometheus-operator ecosystem, like ServiceMonitors and PodMonitors, for service discovery, performing a function analogous to that of prometheus-operator itself. This is enabled via the `prometheusCR` section in the Collector CR. See below for a minimal example: ```yaml apiVersion: opentelemetry.io/v1alpha1 kind: OpenTelemetryCollector metadata: name: collector-with-ta-prometheus-cr spec: mode: statefulset targetAllocator: enabled: true serviceAccount: everything-prometheus-operator-needs prometheusCR: enabled: true config: | receivers: prometheus: config: exporters: debug: service: pipelines: metrics: receivers: [prometheus] processors: [] exporters: [debug] ``` ## Compatibility matrix ### OpenTelemetry Operator vs. OpenTelemetry Collector The OpenTelemetry Operator follows the same versioning as the operand (OpenTelemetry Collector) up to the minor part of the version. For example, the OpenTelemetry Operator v0.18.1 tracks OpenTelemetry Collector 0.18.0. The patch part of the version indicates the patch level of the operator itself, not that of OpenTelemetry Collector. Whenever a new patch version is released for OpenTelemetry Collector, we'll release a new patch version of the operator. By default, the OpenTelemetry Operator ensures consistent versioning between itself and the managed `OpenTelemetryCollector` resources. That is, if the OpenTelemetry Operator is based on version `0.40.0`, it will create resources with an underlying OpenTelemetry Collector at version `0.40.0`. When a custom `Spec.Image` is used with an `OpenTelemetryCollector` resource, the OpenTelemetry Operator will not manage this versioning and upgrading. In this scenario, it is best practice that the OpenTelemetry Operator version should match the underlying core version. Given a `OpenTelemetryCollector` resource with a `Spec.Image` configured to a custom image based on underlying OpenTelemetry Collector at version `0.40.0`, it is recommended that the OpenTelemetry Operator is kept at version `0.40.0`. ### OpenTelemetry Operator vs. Kubernetes vs. Cert Manager We strive to be compatible with the widest range of Kubernetes versions as possible, but some changes to Kubernetes itself require us to break compatibility with older Kubernetes versions, be it because of code incompatibilities, or in the name of maintainability. Every released operator will support a specific range of Kubernetes versions, to be determined at the latest during the release. We use `cert-manager` for some features of this operator and the third column shows the versions of the `cert-manager` that are known to work with this operator's versions. The OpenTelemetry Operator *might* work on versions outside of the given range, but when opening new issues, please make sure to test your scenario on a supported version. | OpenTelemetry Operator | Kubernetes | Cert-Manager | |------------------------|----------------------|---------------------| | v0.92.0 | v1.23 to v1.29 | v1 | | v0.91.0 | v1.23 to v1.29 | v1 | | v0.90.0 | v1.23 to v1.28 | v1 | | v0.89.0 | v1.23 to v1.28 | v1 | | v0.88.0 | v1.23 to v1.28 | v1 | | v0.87.0 | v1.23 to v1.28 | v1 | | v0.86.0 | v1.23 to v1.28 | v1 | | v0.85.0 | v1.19 to v1.28 | v1 | | v0.84.0 | v1.19 to v1.28 | v1 | | v0.83.0 | v1.19 to v1.27 | v1 | | v0.82.0 | v1.19 to v1.27 | v1 | | v0.81.0 | v1.19 to v1.27 | v1 | | v0.80.0 | v1.19 to v1.27 | v1 | | v0.79.0 | v1.19 to v1.27 | v1 | | v0.78.0 | v1.19 to v1.27 | v1 | | v0.77.0 | v1.19 to v1.26 | v1 | | v0.76.1 | v1.19 to v1.26 | v1 | | v0.75.0 | v1.19 to v1.26 | v1 | | v0.74.0 | v1.19 to v1.26 | v1 | | v0.73.0 | v1.19 to v1.26 | v1 | | v0.72.0 | v1.19 to v1.26 | v1 | | v0.71.0 | v1.19 to v1.25 | v1 | | v0.70.0 | v1.19 to v1.25 | v1 | ## Contributing and Developing Please see [CONTRIBUTING.md](CONTRIBUTING.md). In addition to the [core responsibilities](https://github.com/open-telemetry/community/blob/main/community-membership.md) the operator project requires approvers and maintainers to be responsible for releasing the project. See [RELEASE.md](./RELEASE.md) for more information and release schedule. Approvers ([@open-telemetry/operator-approvers](https://github.com/orgs/open-telemetry/teams/operator-approvers)): - [Benedikt Bongartz](https://github.com/frzifus), Red Hat - [Tyler Helmuth](https://github.com/TylerHelmuth), Honeycomb - [Yuri Oliveira Sa](https://github.com/yuriolisa), Red Hat - [Mikołaj Świątek](https://github.com/swiatekm-sumo), Sumo Logic Emeritus Approvers: - [Anthony Mirabella](https://github.com/Aneurysm9), AWS - [Dmitrii Anoshin](https://github.com/dmitryax), Splunk - [Jay Camp](https://github.com/jrcamp), Splunk - [James Bebbington](https://github.com/james-bebbington), Google - [Owais Lone](https://github.com/owais), Splunk - [Pablo Baeyens](https://github.com/mx-psi), DataDog Target Allocator Maintainers ([@open-telemetry/operator-ta-maintainers](https://github.com/orgs/open-telemetry/teams/operator-ta-maintainers)): - [Anthony Mirabella](https://github.com/Aneurysm9), AWS - [Kristina Pathak](https://github.com/kristinapathak), Lightstep - [Sebastian Poxhofer](https://github.com/secustor) Maintainers ([@open-telemetry/operator-maintainers](https://github.com/orgs/open-telemetry/teams/operator-maintainers)): - [Jacob Aronoff](https://github.com/jaronoff97), Lightstep - [Pavol Loffay](https://github.com/pavolloffay), Red Hat - [Vineeth Pothulapati](https://github.com/VineethReddy02), Timescale Emeritus Maintainers - [Alex Boten](https://github.com/codeboten), Lightstep - [Bogdan Drutu](https://github.com/BogdanDrutu), Splunk - [Juraci Paixão Kröhling](https://github.com/jpkrohling), Grafana Labs - [Tigran Najaryan](https://github.com/tigrannajaryan), Splunk Learn more about roles in the [community repository](https://github.com/open-telemetry/community/blob/main/community-membership.md). Thanks to all the people who already contributed! [![Contributors][contributors-img]][contributors] ## License [Apache 2.0 License](./LICENSE). [github-workflow]: https://github.com/open-telemetry/opentelemetry-operator/actions [github-workflow-img]: https://github.com/open-telemetry/opentelemetry-operator/workflows/Continuous%20Integration/badge.svg [goreport-img]: https://goreportcard.com/badge/github.com/open-telemetry/opentelemetry-operator [goreport]: https://goreportcard.com/report/github.com/open-telemetry/opentelemetry-operator [godoc-img]: https://godoc.org/github.com/open-telemetry/opentelemetry-operator?status.svg [godoc]: https://godoc.org/github.com/open-telemetry/opentelemetry-operator/pkg/apis/opentelemetry/v1alpha1#OpenTelemetryCollector [contributors]: https://github.com/open-telemetry/opentelemetry-operator/graphs/contributors [contributors-img]: https://contributors-img.web.app/image?repo=open-telemetry/opentelemetry-operator