* 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 = { })
| 330 | * @param options options |
| 331 | */ |
| 332 | public addMetadata(type: string, data: any, options: MetadataOptions = { }): void { |
| 333 | if (data == null) { |
| 334 | return; |
| 335 | } |
| 336 | |
| 337 | const node = this; |
| 338 | function getTrace() { |
| 339 | if (options.stackTraceOverride && options.stackTraceOverride.length > 0) { |
| 340 | return options.stackTraceOverride; |
| 341 | } |
| 342 | const shouldTrace = options.stackTrace ?? false; |
| 343 | return shouldTrace ? captureStackTrace(options.traceFromFunction ?? node.addMetadata) : undefined; |
| 344 | } |
| 345 | |
| 346 | if (!this._metadata) { |
| 347 | this._metadata = []; |
| 348 | } |
| 349 | this._metadata.push({ type, data, trace: getTrace() }); |
| 350 | } |
| 351 | |
| 352 | /** |
| 353 | * Returns the root of the construct tree. |