@@ -61,61 +61,26 @@ export function createLoggerProvider(
6161 ...( apiKey ? { 'X-Goog-Api-Key' : apiKey } : { } )
6262 }
6363 } ,
64- dynamicHeaderProviders
64+ dynamicHeaderProviders ,
65+ dynamicLogAttributeProviders
6566 ) ;
6667
6768 return new LoggerProvider ( {
6869 resource,
69- processors : [
70- new BatchLogRecordProcessor (
71- new AsyncAttributeLogExporter ( logExporter , dynamicLogAttributeProviders )
72- )
73- ] ,
70+ processors : [ new BatchLogRecordProcessor ( logExporter ) ] ,
7471 logRecordLimits : { }
7572 } ) ;
7673}
7774
78- /** A log exporter that appends log entries with resolved async attributes before exporting. */
79- class AsyncAttributeLogExporter implements LogRecordExporter {
80- private readonly _delegate : LogRecordExporter ;
81-
82- constructor (
83- exporter : OTLPLogExporter ,
84- private dynamicLogAttributeProviders : DynamicLogAttributeProvider [ ]
85- ) {
86- this . _delegate = exporter ;
87- }
88-
89- async export (
90- logs : ReadableLogRecord [ ] ,
91- resultCallback : ( result : ExportResult ) => void
92- ) : Promise < void > {
93- await Promise . all (
94- this . dynamicLogAttributeProviders . map ( async provider => {
95- const attribute = await provider . getAttribute ( ) ;
96- if ( attribute ) {
97- logs . forEach ( log => {
98- log . attributes [ attribute [ 0 ] ] = attribute [ 1 ] ;
99- } ) ;
100- }
101- } )
102- ) ;
103- this . _delegate . export ( logs , resultCallback ) ;
104- }
105-
106- shutdown ( ) : Promise < void > {
107- return this . _delegate . shutdown ( ) ;
108- }
109- }
110-
111- /** OTLP exporter that uses custom FetchTransport. */
75+ /** OTLP exporter that uses custom FetchTransport and resolves async attributes. */
11276class OTLPLogExporter
11377 extends OTLPExporterBase < ReadableLogRecord [ ] >
11478 implements LogRecordExporter
11579{
11680 constructor (
11781 config : OTLPExporterConfigBase = { } ,
118- dynamicHeaderProviders : DynamicHeaderProvider [ ] = [ ]
82+ dynamicHeaderProviders : DynamicHeaderProvider [ ] = [ ] ,
83+ private dynamicLogAttributeProviders : DynamicLogAttributeProvider [ ] = [ ]
11984 ) {
12085 super (
12186 createOtlpNetworkExportDelegate (
@@ -133,4 +98,21 @@ class OTLPLogExporter
13398 )
13499 ) ;
135100 }
101+
102+ override async export (
103+ logs : ReadableLogRecord [ ] ,
104+ resultCallback : ( result : ExportResult ) => void
105+ ) : Promise < void > {
106+ await Promise . all (
107+ this . dynamicLogAttributeProviders . map ( async provider => {
108+ const attribute = await provider . getAttribute ( ) ;
109+ if ( attribute ) {
110+ logs . forEach ( log => {
111+ log . attributes [ attribute [ 0 ] ] = attribute [ 1 ] ;
112+ } ) ;
113+ }
114+ } )
115+ ) ;
116+ super . export ( logs , resultCallback ) ;
117+ }
136118}
0 commit comments