1
+ import { SourceMapper as DDSourceMapper } from '@datadog/pprof' ;
2
+
1
3
import { PyroscopeApiExporter } from '../pyroscope-api-exporter.js' ;
4
+ import { PyroscopeConfig } from '../pyroscope-config.js' ;
5
+ import { SourceMapper } from '../sourcemapper.js' ;
2
6
import { ContinuousProfiler } from './continuous-profiler.js' ;
3
- import { WallProfiler , WallProfilerStartArgs } from './wall-profiler.js' ;
4
7
import { HeapProfiler , HeapProfilerStartArgs } from './heap-profiler.js' ;
5
- import { PyroscopeConfig } from '../pyroscope-config .js' ;
8
+ import { WallProfiler , WallProfilerStartArgs } from './wall-profiler .js' ;
6
9
7
10
const MICROS_PER_SECOND = 1e6 ;
8
11
const MS_PER_SECOND = 1e3 ;
@@ -76,7 +79,7 @@ export class PyroscopeProfiler {
76
79
flushIntervalMs : flushIntervalMs ,
77
80
profiler : new HeapProfiler ( ) ,
78
81
startArgs : {
79
- sourceMapper : config . sourceMapper ,
82
+ sourceMapper : this . toDDSourceMapper ( config . sourceMapper ) ,
80
83
samplingIntervalBytes :
81
84
config . heap ?. samplingIntervalBytes ?? DEFAULT_SAMPLING_INTERVAL_BYTES ,
82
85
stackDepth : config . heap ?. stackDepth ?? DEFAULT_STACK_DEPTH ,
@@ -95,7 +98,7 @@ export class PyroscopeProfiler {
95
98
flushIntervalMs : flushIntervalMs ,
96
99
profiler : new WallProfiler ( ) ,
97
100
startArgs : {
98
- sourceMapper : config . sourceMapper ,
101
+ sourceMapper : this . toDDSourceMapper ( config . sourceMapper ) ,
99
102
samplingDurationMs :
100
103
config . wall ?. samplingDurationMs ?? DEFAULT_SAMPLING_DURATION_MS ,
101
104
samplingIntervalMicros :
@@ -105,4 +108,28 @@ export class PyroscopeProfiler {
105
108
} ,
106
109
} ) ;
107
110
}
111
+
112
+ /**
113
+ * Converts a (Pyroscope) `SourceMapper` to a (DataDog) `SourceMapper`. These
114
+ * two types have the same shape, but since the DataDog SourceMapper has a
115
+ * private field `getMappingInfo`, we cannot use these two classes
116
+ * interchangeably.
117
+ *
118
+ * For a more detailed explanation as to why the private method makes the
119
+ * typical TypeScript type conversion impossible, see:
120
+ *
121
+ * https://github.com/microsoft/TypeScript/issues/7755#issuecomment-204161372
122
+ *
123
+ * @param sourceMapper A Pyroscope `SourceMapper`.
124
+ * @return A DataDog `SourceMapper`.
125
+ */
126
+ private toDDSourceMapper (
127
+ sourceMapper : SourceMapper | undefined
128
+ ) : DDSourceMapper | undefined {
129
+ if ( ! sourceMapper ) {
130
+ return undefined ;
131
+ }
132
+
133
+ return sourceMapper as unknown as DDSourceMapper ;
134
+ }
108
135
}
0 commit comments