Skip to content

Commit

Permalink
feat(sns): add TracingConfig prop (#29783)
Browse files Browse the repository at this point in the history
### 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*
  • Loading branch information
jun1-t authored Apr 12, 2024
1 parent ece7eb6 commit f14b60f
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 7 deletions.

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',
});
});
});
});

0 comments on commit f14b60f

Please sign in to comment.