import * as ecs from "aws-cdk-lib/aws-ecs"; import { RetentionDays } from "aws-cdk-lib/aws-logs"; import * as constructs from "constructs"; import type { FargateService } from "./fargate-service"; export interface OpenTelemetryCollectorsProps { service: FargateService; /** @default 6 months **/ logRetention?: RetentionDays; /** @default "amazon/aws-otel-collector:v0.49.0" */ dockerImage?: string; /** Should be kept as `undefined` unless you know what you are doing. * This is the YAML config for the OpenTelemetry collector sidecar. * * An example of a config can be found at https://github.com/aws-observability/aws-otel-collector/blob/0ae198c7e7b8c43bcc8715f54e52c879c04407b6/config/ecs/container-insights/otel-task-metrics-config.yaml * * @default a file in `assets` tuned to work for aws and strips known high-cardinality metrics (like those containing IP addresses and ports) */ awsOtelConfig?: string; /** Overrides for the sidecar container. * You do not need to specify this. * * Defaults: * - cpu: 32 units * - memory reservation: 24 MiB * - memory limit: 256 MiB */ containerProps?: SidecarContainerProps; } /** * Methods to enable collection of Open Telemetry (otel) data of a {@link FargateService} * using a docker container with an otel agent. * * * An example of a Java auto-instrumentation agent in Docker can be found * [in liflig-rest-baseline Dockerfile](https://github.com/capralifecycle/liflig-rest-service-baseline/blob/a29b5a472c982aa7ce04d09d0e7cfdc92a6cc977/docker/Dockerfile#L9-L29). * * The agent must be configured to output metrics to a collector. * That collector is what this construct provides. * Usually, the agent is specified in the Dockerfile or as a dependency/library, * and configured in the Dockerfile or in the application source code. * * Use this construct on a {@link FargateService} by constructing a new instance of {@link OpenTelemetryCollectors} * and calling the {@link addOpenTelemetryCollectorSidecar} method on it. * * ```ts * const service = FargateService(...); * * new OpenTelemetryCollectors(this, "OtelSidecar").addOpenTelemetryCollectorSidecar(service) * ``` * * The sidecar exposes these ports to your service: * - udp 2000 : AWS XRay * - tcp 4317 : OpenTelemetry collection GRPC * - tcp 4318 : OpenTelemetry collection HTTP * * --- * * You can also disable the OpenTelemetry instrumentation agent * for Java-based services, * by setting the appropriate environment variable with {@link disableOpenTelemetryJavaAgent}: * ```ts * const service = FargateService(...); * * OpenTelemetryCollectors.disableOpenTelemetryJavaAgent(service) * ``` * * @see OpenTelemetryCollectors.addOpenTelemetryCollectorSidecar */ export declare class OpenTelemetryCollectors extends constructs.Construct { private readonly props; constructor(scope: constructs.Construct, id: string, props: OpenTelemetryCollectorsProps); /** * The OpenTelemetry Java agent may run by default in the Docker image. * This method will tell the agent to disable itself. * * You might want to do this to avoid overhead or error logs from failed * connection attempts to the otel collector. */ disableOpenTelemetryJavaAgent(): void; /** * The OpenTelemetry Java agent may run by default in the Docker image. * This method will tell the agent to disable itself. * * You might want to do this to avoid overhead or error logs from failed * connection attempts to the otel collector. * @param service */ static disableOpenTelemetryJavaAgent(service: FargateService): void; /** * Adds a sidecar with an AWS Distro OpenTelemetry Collector. * https://aws-otel.github.io/docs/setup/ecs * * You also need to add either the Java SDK for OTel or a Java agent, * to capture telemetry and send to this collector. */ addOpenTelemetryCollectorSidecar(): void; } export type SidecarContainerProps = Pick;