* 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 = { })
| 317 | * @param options options |
| 318 | */ |
| 319 | public addMetadata(type: string, data: any, options: MetadataOptions = { }): void { |
| 320 | if (data == null) { |
| 321 | return; |
| 322 | } |
| 323 | |
| 324 | const node = this; |
| 325 | function getTrace() { |
| 326 | if (options.stackTraceOverride && options.stackTraceOverride.length > 0) { |
| 327 | return options.stackTraceOverride; |
| 328 | } |
| 329 | const shouldTrace = options.stackTrace ?? false; |
| 330 | return shouldTrace ? captureStackTrace(options.traceFromFunction ?? node.addMetadata) : undefined; |
| 331 | } |
| 332 | |
| 333 | if (!this._metadata) { |
| 334 | this._metadata = []; |
| 335 | } |
| 336 | this._metadata.push({ type, data, trace: getTrace() }); |
| 337 | } |
| 338 | |
| 339 | /** |
| 340 | * Returns the root of the construct tree. |