@@ -9,6 +9,7 @@ import { ServiceConfigurationOptions } from 'aws-sdk/lib/service'
9
9
import { AwsContext } from './awsContext'
10
10
import { DevSettings } from './settings'
11
11
import { getUserAgent } from './telemetry/util'
12
+ import { telemetry } from './telemetry/telemetry'
12
13
13
14
// These are not on the public API but are very useful for logging purposes.
14
15
// Tests guard against the possibility that these values change unexpectedly.
@@ -131,14 +132,37 @@ export class DefaultAWSClientBuilder implements AWSClientBuilder {
131
132
132
133
const apiConfig = ( opt as { apiConfig ?: { metadata ?: Record < string , string > } } | undefined ) ?. apiConfig
133
134
const serviceName =
134
- apiConfig ?. metadata ?. serviceId ?? ( type as unknown as { serviceIdentifier ?: string } ) . serviceIdentifier
135
+ apiConfig ?. metadata ?. serviceId ?. toLowerCase ( ) ??
136
+ ( type as unknown as { serviceIdentifier ?: string } ) . serviceIdentifier
137
+
135
138
if ( serviceName ) {
136
- opt . endpoint = settings . get ( 'endpoints' , { } ) [ serviceName . toLowerCase ( ) ] ?? opt . endpoint
139
+ opt . endpoint = settings . get ( 'endpoints' , { } ) [ serviceName ] ?? opt . endpoint
137
140
}
138
141
139
142
const service = new type ( opt )
140
143
const originalSetup = service . setupRequestListeners . bind ( service )
141
144
145
+ // Record request IDs to the current context, potentially overriding the field if
146
+ // multiple API calls are made in the same context. We only do failures as successes
147
+ // are generally uninteresting and noisy.
148
+ listeners . push ( request => {
149
+ request . on ( 'error' , err => {
150
+ if ( ! err . retryable ) {
151
+ // TODO: update codegen so `record` enumerates all fields as a flat object instead of
152
+ // intersecting all of the definitions
153
+ interface RequestData {
154
+ requestId ?: string
155
+ requestServiceType ?: string
156
+ }
157
+
158
+ telemetry . record ( {
159
+ requestId : err . requestId ,
160
+ requestServiceType : serviceName ,
161
+ } satisfies RequestData as any )
162
+ }
163
+ } )
164
+ } )
165
+
142
166
service . setupRequestListeners = ( request : Request < any , AWSError > ) => {
143
167
originalSetup ( request )
144
168
listeners . forEach ( l => l ( request as AWS . Request < any , AWSError > & RequestExtras ) )
0 commit comments