Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sns): add TracingConfig prop #29783

Merged
merged 4 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,14 @@
"TopicName": "fooTopicSignatureVersion"
}
},
"MyTopicTracingConfigE05AF123": {
"Type": "AWS::SNS::Topic",
"Properties": {
"DisplayName": "fooDisplayNameTracingConfig",
"TopicName": "fooTopicTracingConfig",
"TracingConfig": "Active"
}
},
"MyTopic288CE2107": {
"Type": "AWS::SNS::Topic",
"Properties": {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Key } from 'aws-cdk-lib/aws-kms';
import { App, Stack, StackProps, RemovalPolicy, Duration } from 'aws-cdk-lib';
import { LoggingProtocol, Topic } from 'aws-cdk-lib/aws-sns';
import { LoggingProtocol, Topic, TracingConfig } from 'aws-cdk-lib/aws-sns';
import { ManagedPolicy, PolicyDocument, PolicyStatement, Role, ServicePrincipal } from 'aws-cdk-lib/aws-iam';

class SNSInteg extends Stack {
Expand Down Expand Up @@ -51,6 +51,13 @@ class SNSInteg extends Stack {
signatureVersion: '2',
});

// Topic with tracingConfig
new Topic(this, 'MyTopicTracingConfig', {
topicName: 'fooTopicTracingConfig',
displayName: 'fooDisplayNameTracingConfig',
tracingConfig: TracingConfig.ACTIVE,
});

// Can import topic
const topic2 = new Topic(this, 'MyTopic2', {
topicName: 'fooTopic2',
Expand Down
16 changes: 16 additions & 0 deletions packages/aws-cdk-lib/aws-sns/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -318,3 +318,19 @@ const topic = new sns.Topic(this, 'MyTopic', {

**Note**: The `messageRetentionPeriodInDays` property is only available for FIFO topics.

## TracingConfig

Tracing mode of an Amazon SNS topic.

If PassThrough, the topic passes trace headers received from the Amazon SNS publisher to its subscription.
If set to Active, Amazon SNS will vend X-Ray segment data to topic owner account if the sampled flag in the tracing header is true.

The default TracingConfig is `TracingConfig.PASS_THROUGH`.

Example with a tracingConfig set to Active:

```ts
const topic = new sns.Topic(this, 'MyTopic', {
tracingConfig: sns.TracingConfig.ACTIVE,
});
```
25 changes: 25 additions & 0 deletions packages/aws-cdk-lib/aws-sns/lib/topic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,15 @@ export interface TopicProps {
* @default 1
*/
readonly signatureVersion?: string;

/**
* Tracing mode of an Amazon SNS topic.
*
* @see https://docs.aws.amazon.com/sns/latest/dg/sns-active-tracing.html
*
* @default TracingConfig.PASS_THROUGH
*/
readonly tracingConfig?: TracingConfig;
}

/**
Expand Down Expand Up @@ -153,6 +162,21 @@ export enum LoggingProtocol {
APPLICATION = 'application',
}

/**
* The tracing mode of an Amazon SNS topic
*/
export enum TracingConfig {
/**
* The mode that topic passes trace headers received from the Amazon SNS publisher to its subscription.
*/
PASS_THROUGH = 'PassThrough',

/**
* The mode that Amazon SNS vend X-Ray segment data to topic owner account if the sampled flag in the tracing header is true.
*/
ACTIVE = 'Active',
}

/**
* Represents an SNS topic defined outside of this stack.
*/
Expand Down Expand Up @@ -283,6 +307,7 @@ export class Topic extends TopicBase {
fifoTopic: props.fifo,
signatureVersion: props.signatureVersion,
deliveryStatusLogging: Lazy.any({ produce: () => this.renderLoggingConfigs() }, { omitEmptyArray: true }),
tracingConfig: props.tracingConfig,
});

this.topicArn = this.getResourceArnAttribute(resource.ref, {
Expand Down
18 changes: 18 additions & 0 deletions packages/aws-cdk-lib/aws-sns/test/sns.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -801,4 +801,22 @@ describe('Topic', () => {
).toThrow('`messageRetentionPeriodInDays` is only valid for FIFO SNS topics');
});
});

describe('tracingConfig', () => {
test('specify tracingConfig', () => {
// GIVEN
const app = new cdk.App();
const stack = new cdk.Stack(app);

// WHEN
new sns.Topic(stack, 'MyTopic', {
tracingConfig: sns.TracingConfig.ACTIVE,
});

// THEN
Template.fromStack(stack).hasResourceProperties('AWS::SNS::Topic', {
'TracingConfig': 'Active',
});
});
});
});