> **Experimental**
>
> `@aws-cdk/aws-applicationsignals-alpha` is an [**experimental**](/stability) (alpha) package: its API may change in any release, without a major version bump.
# TraceExporting

OpenTelemetry trace exporter and sampling configurations.

Contains constants for trace endpoints, sampling strategies, and propagation formats.

- Stability: [Experimental](/cdk/api/stability.html)
- Source: [`lib/enablement/constants.ts`](https://github.com/aws/aws-cdk/blob/v2.275.0-alpha.0/packages/@aws-cdk/aws-applicationsignals-alpha/lib/enablement/constants.ts#L64)

## Example

```ts
import { Construct } from 'constructs';
import * as appsignals from '@aws-cdk/aws-applicationsignals-alpha';
import * as cdk from 'aws-cdk-lib';
import * as ec2 from 'aws-cdk-lib/aws-ec2';
import * as ecs from 'aws-cdk-lib/aws-ecs';
import { PrivateDnsNamespace } from 'aws-cdk-lib/aws-servicediscovery';

class MyStack extends cdk.Stack {
  public constructor(scope?: Construct, id?: string, props: cdk.StackProps = {}) {
    super(scope, id, props);

    const vpc = new ec2.Vpc(this, 'TestVpc', {});
    const cluster = new ecs.Cluster(this, 'TestCluster', { vpc });
    const dnsNamespace = new PrivateDnsNamespace(this, 'Namespace', {
      vpc,
      name: 'local',
    });
    const securityGroup = new ec2.SecurityGroup(this, 'ECSSG', { vpc });
    securityGroup.addIngressRule(securityGroup, ec2.Port.tcpRange(0, 65535));

    // Define Task Definition for CloudWatch agent (Replica)
    const cwAgentTaskDefinition = new ecs.FargateTaskDefinition(this, 'CloudWatchAgentTaskDefinition', {});

    new appsignals.CloudWatchAgentIntegration(this, 'CloudWatchAgentIntegration', {
      taskDefinition: cwAgentTaskDefinition,
      containerName: 'ecs-cwagent',
      enableLogging: false,
      cpu: 128,
      memoryLimitMiB: 64,
      portMappings: [
        {
          name: 'cwagent-4316',
          containerPort: 4316,
          hostPort: 4316,
        },
        {
          name: 'cwagent-2000',
          containerPort: 2000,
          hostPort: 2000,
        },
      ],
    });

    // Create the CloudWatch Agent replica service with service connect
    new ecs.FargateService(this, 'CloudWatchAgentService', {
      cluster: cluster,
      taskDefinition: cwAgentTaskDefinition,
      securityGroups: [securityGroup],
      serviceConnectConfiguration: {
        namespace: dnsNamespace.namespaceArn,
        services: [
          {
            portMappingName: 'cwagent-4316',
            dnsName: 'cwagent-4316-http',
            port: 4316,
          },
          {
            portMappingName: 'cwagent-2000',
            dnsName: 'cwagent-2000-http',
            port: 2000,
          },
        ],
      },
      desiredCount: 1,
    });

    // Define Task Definition for user application
    const sampleAppTaskDefinition = new ecs.FargateTaskDefinition(this, 'SampleAppTaskDefinition', {});

    sampleAppTaskDefinition.addContainer('app', {
      image: ecs.ContainerImage.fromRegistry('test/sample-app'),
      cpu: 0,
      memoryLimitMiB: 512,
    });

    // Overwrite environment variables to connect to the CloudWatch Agent service just created
    new appsignals.ApplicationSignalsIntegration(this, 'ApplicationSignalsIntegration', {
      taskDefinition: sampleAppTaskDefinition,
      instrumentation: {
        sdkVersion: appsignals.PythonInstrumentationVersion.V0_8_0,
      },
      serviceName: 'sample-app',
      overrideEnvironments: [
        {
          name: appsignals.CommonExporting.OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT,
          value: 'http://cwagent-4316-http:4316/v1/metrics',
        },
        {
          name: appsignals.TraceExporting.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT,
          value: 'http://cwagent-4316-http:4316/v1/traces',
        },
        {
          name: appsignals.TraceExporting.OTEL_TRACES_SAMPLER_ARG,
          value: 'endpoint=http://cwagent-2000-http:2000',
        },
      ],
    });

    // Create ECS Service with service connect configuration
    new ecs.FargateService(this, 'MySampleApp', {
      cluster: cluster,
      taskDefinition: sampleAppTaskDefinition,
      serviceConnectConfiguration: {
        namespace: dnsNamespace.namespaceArn,
      },
      desiredCount: 1,
    });
  }
}
```

## Initializer

```ts
new TraceExporting()
```

## Properties

- `OTEL_EXPORTER_OTLP_TRACES_ENDPOINT`: string (static) — Endpoint configuration for OTLP traces.

- `OTEL_EXPORTER_OTLP_TRACES_ENDPOINT_LOCAL_CWA`: string (static) — Local CloudWatch Agent endpoint for traces.

- `OTEL_PROPAGATORS`: string (static) — Configuration for trace context propagation.

- `OTEL_PROPAGATORS_APPLICATION_SIGNALS`: string (static) — Supported propagation formats for Application Signals.

- `OTEL_TRACES_SAMPLER`: string (static) — Sampling configuration for traces.

- `OTEL_TRACES_SAMPLER_ALWAYS_OFF`: string (static) — Sample no traces.

- `OTEL_TRACES_SAMPLER_ALWAYS_ON`: string (static) — Sample all traces.

- `OTEL_TRACES_SAMPLER_ARG`: string (static) — Arguments for trace sampler configuration.

- `OTEL_TRACES_SAMPLER_ARG_LOCAL_CWA`: string (static) — Local CloudWatch Agent endpoint for sampler.

- `OTEL_TRACES_SAMPLER_PARENT_BASED_ALWAYS_OFF`: string (static) — Parent-based always off sampling.

- `OTEL_TRACES_SAMPLER_PARENT_BASED_ALWAYS_ON`: string (static) — Parent-based always on sampling.

- `OTEL_TRACES_SAMPLER_PARENT_BASED_TRACEID_RATIO`: string (static) — Parent-based trace ID ratio sampling.

- `OTEL_TRACES_SAMPLER_TRACEID_RATIO`: string (static) — Trace ID ratio based sampling.

- `OTEL_TRACES_SAMPLER_XRAY`: string (static) — X-Ray sampling strategy.
