1+ import type { Context , Span , SpanOptions } from '@opentelemetry/api'
2+ import type { Metric } from '../client'
3+ import type { ErrorMessageType } from '../client/types/shared-types'
4+
5+ export interface Observability {
6+
7+ /**
8+ * @deprecated with replacement by `consumeError` for an in-app stacktrace.
9+ */
10+ error : ( message : string , payload ?: { [ key : string ] : string } ) => void
11+ /**
12+ * Calling this method will report metrics to Highlight. You can graph metrics or configure
13+ * alerts on metrics that exceed a threshold.
14+ * @see {@link https://docs.highlight.run/frontend-observability } for more information.
15+ */
16+ metrics : ( metrics : Metric [ ] ) => void
17+ /**
18+ * Record arbitrary metric values via as a Gauge.
19+ * A Gauge records any point-in-time measurement, such as the current CPU utilization %.
20+ * Values with the same metric name and attributes are aggregated via the OTel SDK.
21+ * See https://opentelemetry.io/docs/specs/otel/metrics/data-model/ for more details.
22+ */
23+ recordMetric : ( metric : Metric ) => void
24+ /**
25+ * Record arbitrary metric values via as a Counter.
26+ * A Counter efficiently records an increment in a metric, such as number of cache hits.
27+ * Values with the same metric name and attributes are aggregated via the OTel SDK.
28+ * See https://opentelemetry.io/docs/specs/otel/metrics/data-model/ for more details.
29+ */
30+ recordCount : ( metric : Metric ) => void
31+ /**
32+ * Record arbitrary metric values via as a Counter.
33+ * A Counter efficiently records an increment in a metric, such as number of cache hits.
34+ * Values with the same metric name and attributes are aggregated via the OTel SDK.
35+ * See https://opentelemetry.io/docs/specs/otel/metrics/data-model/ for more details.
36+ */
37+ recordIncr : ( metric : Omit < Metric , 'value' > ) => void
38+ /**
39+ * Record arbitrary metric values via as a Histogram.
40+ * A Histogram efficiently records near-by point-in-time measurement into a bucketed aggregate.
41+ * Values with the same metric name and attributes are aggregated via the OTel SDK.
42+ * See https://opentelemetry.io/docs/specs/otel/metrics/data-model/ for more details.
43+ */
44+ recordHistogram : ( metric : Metric ) => void
45+ /**
46+ * Record arbitrary metric values via as a UpDownCounter.
47+ * A UpDownCounter efficiently records an increment or decrement in a metric, such as number of paying customers.
48+ * Values with the same metric name and attributes are aggregated via the OTel SDK.
49+ * See https://opentelemetry.io/docs/specs/otel/metrics/data-model/ for more details.
50+ */
51+ recordUpDownCounter : ( metric : Metric ) => void
52+ /**
53+ * Starts a new span for tracing in Highlight. The span will be ended when the
54+ * callback function returns.
55+ *
56+ * @example
57+ * ```typescript
58+ * H.startSpan('span-name', callbackFn)
59+ * ```
60+ * @example
61+ * ```typescript
62+ * H.startSpan('span-name', options, callbackFn)
63+ * ```
64+ * @example
65+ * ```typescript
66+ * H.startSpan('span-name', options, context, callbackFn)
67+ * ```
68+ * @example
69+ * ```typescript
70+ * H.startSpan('span-name', async (span) => {
71+ * span.setAttribute('key', 'value')
72+ * await someAsyncFunction()
73+ * })
74+ * ```
75+ *
76+ * @param name The name of the span.
77+ * @param options Options for the span.
78+ * @param context The context for the span.
79+ * @param callbackFn The function to run in the span.
80+ */
81+ startSpan : {
82+ < F extends ( span ?: Span ) => ReturnType < F > > (
83+ name : string ,
84+ fn : F ,
85+ ) : ReturnType < F >
86+ < F extends ( span ?: Span ) => ReturnType < F > > (
87+ name : string ,
88+ options : SpanOptions ,
89+ fn : F ,
90+ ) : ReturnType < F >
91+ < F extends ( span ?: Span ) => ReturnType < F > > (
92+ name : string ,
93+ options : SpanOptions ,
94+ context : Context ,
95+ fn : F ,
96+ ) : ReturnType < F >
97+ }
98+ /**
99+ * Starts a new span for tracing in Highlight. The span will be ended when the
100+ * `end()` is called on the span. It returns whatever is returned from the
101+ * callback function.
102+ *
103+ * @example
104+ * ```typescript
105+ * H.startManualSpan('span-name', options, (span) => {
106+ * span.addEvent('event-name', { key: 'value' })
107+ * span.setAttribute('key', 'value')
108+ * await someAsyncFunction()
109+ * span.end()
110+ * })
111+ * ```
112+ *
113+ * @example
114+ * ```typescript
115+ * const span = H.startManualSpan('span-name', (s) => s)
116+ * span.addEvent('event-name', { key: 'value' })
117+ * await someAsyncFunction()
118+ * span.end()
119+ * ```
120+ *
121+ * @param name The name of the span.
122+ * @param options Options for the span.
123+ * @param context The context for the span.
124+ * @param fn The function to run in the span.
125+ */
126+ startManualSpan : {
127+ < F extends ( span : Span ) => ReturnType < F > > (
128+ name : string ,
129+ fn : F ,
130+ ) : ReturnType < F >
131+ < F extends ( span : Span ) => ReturnType < F > > (
132+ name : string ,
133+ options : SpanOptions ,
134+ fn : F ,
135+ ) : ReturnType < F >
136+ < F extends ( span : Span ) => ReturnType < F > > (
137+ name : string ,
138+ options : SpanOptions ,
139+ context : Context ,
140+ fn : F ,
141+ ) : ReturnType < F >
142+ }
143+ /**
144+ * Calling this method will report an error in Highlight and map it to the current session being recorded.
145+ * A common use case for `H.error` is calling it right outside of an error boundary.
146+ * @see {@link https://docs.highlight.run/grouping-errors } for more information.
147+ */
148+ consumeError : (
149+ error : Error ,
150+ message ?: string ,
151+ payload ?: { [ key : string ] : string } ,
152+ ) => void
153+ /**
154+ * Calling this method will report an error in Highlight
155+ * while allowing additional attributes to be sent over as metadata.
156+ * @see {consumeError} for more information.
157+ */
158+ consume : (
159+ error : Error ,
160+ opts : {
161+ message ?: string
162+ payload ?: object
163+ source ?: string
164+ type ?: ErrorMessageType
165+ } ,
166+ ) => void
167+ }
0 commit comments