* Adds a metadata entry to this construct. * Entries are arbitrary values and will also include a stack trace to allow tracing back to * the code location for when the entry was added. It can be used, for example, to include source * mapping in CloudFormation templates to improve diagnostic
(type: string, data: any, options: MetadataOptions = { })
| 301 | * @param options options |
| 302 | */ |
| 303 | public addMetadata(type: string, data: any, options: MetadataOptions = { }): void { |
| 304 | if (data == null) { |
| 305 | return; |
| 306 | } |
| 307 | |
| 308 | const node = this; |
| 309 | function getTrace() { |
| 310 | if (options.stackTraceOverride && options.stackTraceOverride.length > 0) { |
| 311 | return options.stackTraceOverride; |
| 312 | } |
| 313 | const shouldTrace = options.stackTrace ?? false; |
| 314 | return shouldTrace ? captureStackTrace(options.traceFromFunction ?? node.addMetadata) : undefined; |
| 315 | } |
| 316 | |
| 317 | if (!this._metadata) { |
| 318 | this._metadata = []; |
| 319 | } |
| 320 | this._metadata.push({ type, data, trace: getTrace() }); |
| 321 | } |
| 322 | |
| 323 | /** |
| 324 | * All parent scopes of this construct. |