Skip to content

Commit f14b60f

Browse files
authored
feat(sns): add TracingConfig prop (#29783)
### Issue # (if applicable) Closes #29714 ### Reason for this change Currently, to set the TracingConfig, it is necessary to configure it via L1. So, add TracingConfig props to L2. ### Description of changes added TracingConfig props to topic.ts, sns.test.ts, integ.sns.ts, and README.md for AWS SNS. ### Description of how you validated changes I confirmed with unit test and integ test that it works as expected. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent ece7eb6 commit f14b60f

File tree

8 files changed

+113
-7
lines changed

8 files changed

+113
-7
lines changed

packages/@aws-cdk-testing/framework-integ/test/aws-sns/test/integ.sns.js.snapshot/SNSInteg.assets.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-sns/test/integ.sns.js.snapshot/SNSInteg.template.json

+8
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,14 @@
120120
"TopicName": "fooTopicSignatureVersion"
121121
}
122122
},
123+
"MyTopicTracingConfigE05AF123": {
124+
"Type": "AWS::SNS::Topic",
125+
"Properties": {
126+
"DisplayName": "fooDisplayNameTracingConfig",
127+
"TopicName": "fooTopicTracingConfig",
128+
"TracingConfig": "Active"
129+
}
130+
},
123131
"MyTopic288CE2107": {
124132
"Type": "AWS::SNS::Topic",
125133
"Properties": {

packages/@aws-cdk-testing/framework-integ/test/aws-sns/test/integ.sns.js.snapshot/manifest.json

+7-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-sns/test/integ.sns.js.snapshot/tree.json

+29-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-sns/test/integ.sns.ts

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

66
class SNSInteg extends Stack {
@@ -51,6 +51,13 @@ class SNSInteg extends Stack {
5151
signatureVersion: '2',
5252
});
5353

54+
// Topic with tracingConfig
55+
new Topic(this, 'MyTopicTracingConfig', {
56+
topicName: 'fooTopicTracingConfig',
57+
displayName: 'fooDisplayNameTracingConfig',
58+
tracingConfig: TracingConfig.ACTIVE,
59+
});
60+
5461
// Can import topic
5562
const topic2 = new Topic(this, 'MyTopic2', {
5663
topicName: 'fooTopic2',

packages/aws-cdk-lib/aws-sns/README.md

+16
Original file line numberDiff line numberDiff line change
@@ -318,3 +318,19 @@ const topic = new sns.Topic(this, 'MyTopic', {
318318

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

321+
## TracingConfig
322+
323+
Tracing mode of an Amazon SNS topic.
324+
325+
If PassThrough, the topic passes trace headers received from the Amazon SNS publisher to its subscription.
326+
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.
327+
328+
The default TracingConfig is `TracingConfig.PASS_THROUGH`.
329+
330+
Example with a tracingConfig set to Active:
331+
332+
```ts
333+
const topic = new sns.Topic(this, 'MyTopic', {
334+
tracingConfig: sns.TracingConfig.ACTIVE,
335+
});
336+
```

packages/aws-cdk-lib/aws-sns/lib/topic.ts

+25
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,15 @@ export interface TopicProps {
8686
* @default 1
8787
*/
8888
readonly signatureVersion?: string;
89+
90+
/**
91+
* Tracing mode of an Amazon SNS topic.
92+
*
93+
* @see https://docs.aws.amazon.com/sns/latest/dg/sns-active-tracing.html
94+
*
95+
* @default TracingConfig.PASS_THROUGH
96+
*/
97+
readonly tracingConfig?: TracingConfig;
8998
}
9099

91100
/**
@@ -153,6 +162,21 @@ export enum LoggingProtocol {
153162
APPLICATION = 'application',
154163
}
155164

165+
/**
166+
* The tracing mode of an Amazon SNS topic
167+
*/
168+
export enum TracingConfig {
169+
/**
170+
* The mode that topic passes trace headers received from the Amazon SNS publisher to its subscription.
171+
*/
172+
PASS_THROUGH = 'PassThrough',
173+
174+
/**
175+
* The mode that Amazon SNS vend X-Ray segment data to topic owner account if the sampled flag in the tracing header is true.
176+
*/
177+
ACTIVE = 'Active',
178+
}
179+
156180
/**
157181
* Represents an SNS topic defined outside of this stack.
158182
*/
@@ -283,6 +307,7 @@ export class Topic extends TopicBase {
283307
fifoTopic: props.fifo,
284308
signatureVersion: props.signatureVersion,
285309
deliveryStatusLogging: Lazy.any({ produce: () => this.renderLoggingConfigs() }, { omitEmptyArray: true }),
310+
tracingConfig: props.tracingConfig,
286311
});
287312

288313
this.topicArn = this.getResourceArnAttribute(resource.ref, {

packages/aws-cdk-lib/aws-sns/test/sns.test.ts

+18
Original file line numberDiff line numberDiff line change
@@ -801,4 +801,22 @@ describe('Topic', () => {
801801
).toThrow('`messageRetentionPeriodInDays` is only valid for FIFO SNS topics');
802802
});
803803
});
804+
805+
describe('tracingConfig', () => {
806+
test('specify tracingConfig', () => {
807+
// GIVEN
808+
const app = new cdk.App();
809+
const stack = new cdk.Stack(app);
810+
811+
// WHEN
812+
new sns.Topic(stack, 'MyTopic', {
813+
tracingConfig: sns.TracingConfig.ACTIVE,
814+
});
815+
816+
// THEN
817+
Template.fromStack(stack).hasResourceProperties('AWS::SNS::Topic', {
818+
'TracingConfig': 'Active',
819+
});
820+
});
821+
});
804822
});

0 commit comments

Comments
 (0)