Skip to content

Commit

Permalink
Add retry fields to the current span
Browse files Browse the repository at this point in the history
  • Loading branch information
mairatma committed Oct 10, 2023
1 parent ecb4e28 commit 73084b9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { HttpLogEvents } from '../../../../../tracing/LogEvents'
import { HttpRetryLogFields } from '../../../../../tracing/LogFields'
import { isAbortedOrNetworkErrorOrRouterTimeout } from '../../../../../utils/retry'
import { RequestConfig } from '../../../../typings'
import { TraceableRequestConfig } from '../../../tracing'
import { CustomHttpTags } from '../../../../../tracing/Tags'

function fixConfig(axiosInstance: AxiosInstance, config: RequestConfig) {
if (axiosInstance.defaults.httpAgent === config.httpAgent) {
Expand Down Expand Up @@ -66,6 +66,10 @@ const onResponseError = (http: AxiosInstance) => (error: any) => {
config.transformRequest = [data => data]

config.tracing?.rootSpan?.log({ event: HttpLogEvents.SETUP_REQUEST_RETRY, [HttpRetryLogFields.RETRY_NUMBER]: config.retryCount, [HttpRetryLogFields.RETRY_IN]: delay })
config.tracing?.rootSpan?.addTags({
[CustomHttpTags.HTTP_RETRY_COUNT]: config.retryCount,
[CustomHttpTags.HTTP_RETRY_ERROR_CODE]: error.code
})

return new Promise(resolve => setTimeout(() => resolve(http(config)), delay))
}
Expand Down
3 changes: 3 additions & 0 deletions src/tracing/Tags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ export const enum CustomHttpTags {
HTTP_MEMOIZATION_CACHE_RESULT = 'http.cache.memoization',
HTTP_DISK_CACHE_RESULT = 'http.cache.disk',
HTTP_ROUTER_CACHE_RESULT = 'http.cache.router',

HTTP_RETRY_ERROR_CODE = 'http.retry.error.code',
HTTP_RETRY_COUNT = 'http.retry.count'
}

export const UserlandTags = {
Expand Down

0 comments on commit 73084b9

Please sign in to comment.