@shopify/cli-kit 3.49.6 → 3.50.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/cli-ruby/lib/project_types/theme/commands/console.rb +3 -1
- package/assets/cli-ruby/lib/shopify_cli/theme/file.rb +2 -0
- package/assets/cli-ruby/lib/shopify_cli/theme/repl/auth_dev_server.rb +2 -4
- package/assets/cli-ruby/lib/shopify_cli/theme/repl/remote_evaluator.rb +3 -0
- package/assets/cli-ruby/lib/shopify_cli/theme/repl.rb +4 -3
- package/dist/private/node/constants.d.ts +2 -0
- package/dist/private/node/constants.js +2 -0
- package/dist/private/node/constants.js.map +1 -1
- package/dist/private/node/context/utilities.js +2 -3
- package/dist/private/node/context/utilities.js.map +1 -1
- package/dist/private/node/otel-metrics.d.ts +32 -0
- package/dist/private/node/otel-metrics.js +131 -0
- package/dist/private/node/otel-metrics.js.map +1 -0
- package/dist/private/node/session/authorize.js +8 -5
- package/dist/private/node/session/authorize.js.map +1 -1
- package/dist/private/node/testing/ui.d.ts +4 -2
- package/dist/private/node/testing/ui.js +10 -3
- package/dist/private/node/testing/ui.js.map +1 -1
- package/dist/private/node/ui/components/AutocompletePrompt.js +6 -2
- package/dist/private/node/ui/components/AutocompletePrompt.js.map +1 -1
- package/dist/private/node/ui/components/AutocompletePrompt.test.js +5 -3
- package/dist/private/node/ui/components/AutocompletePrompt.test.js.map +1 -1
- package/dist/private/node/ui/components/DangerousConfirmationPrompt.js +12 -6
- package/dist/private/node/ui/components/DangerousConfirmationPrompt.js.map +1 -1
- package/dist/private/node/ui/components/DangerousConfirmationPrompt.test.js +1 -1
- package/dist/private/node/ui/components/DangerousConfirmationPrompt.test.js.map +1 -1
- package/dist/private/node/ui/components/Prompts/GitDiff.test.js +18 -11
- package/dist/private/node/ui/components/Prompts/GitDiff.test.js.map +1 -1
- package/dist/private/node/ui/components/SelectPrompt.js +8 -4
- package/dist/private/node/ui/components/SelectPrompt.js.map +1 -1
- package/dist/private/node/ui/components/SelectPrompt.test.js +5 -3
- package/dist/private/node/ui/components/SelectPrompt.test.js.map +1 -1
- package/dist/private/node/ui/components/Tasks.js +8 -1
- package/dist/private/node/ui/components/Tasks.js.map +1 -1
- package/dist/private/node/ui/components/TextPrompt.js +7 -3
- package/dist/private/node/ui/components/TextPrompt.js.map +1 -1
- package/dist/private/node/ui/components/TokenizedText.d.ts +10 -1
- package/dist/private/node/ui/components/TokenizedText.js +18 -0
- package/dist/private/node/ui/components/TokenizedText.js.map +1 -1
- package/dist/private/node/ui/components/TokenizedText.test.js +10 -1
- package/dist/private/node/ui/components/TokenizedText.test.js.map +1 -1
- package/dist/private/node/ui/utilities.d.ts +1 -1
- package/dist/public/common/version.d.ts +1 -1
- package/dist/public/common/version.js +1 -1
- package/dist/public/common/version.js.map +1 -1
- package/dist/public/node/analytics.d.ts +2 -0
- package/dist/public/node/analytics.js +48 -10
- package/dist/public/node/analytics.js.map +1 -1
- package/dist/public/node/api/graphql.js +8 -5
- package/dist/public/node/api/graphql.js.map +1 -1
- package/dist/public/node/base-command.js +4 -3
- package/dist/public/node/base-command.js.map +1 -1
- package/dist/public/node/cli.js +5 -2
- package/dist/public/node/cli.js.map +1 -1
- package/dist/public/node/context/local.d.ts +16 -0
- package/dist/public/node/context/local.js +23 -0
- package/dist/public/node/context/local.js.map +1 -1
- package/dist/public/node/error-handler.d.ts +4 -1
- package/dist/public/node/error-handler.js +26 -18
- package/dist/public/node/error-handler.js.map +1 -1
- package/dist/public/node/error.d.ts +1 -1
- package/dist/public/node/error.js +1 -1
- package/dist/public/node/error.js.map +1 -1
- package/dist/public/node/hooks/postrun.js +1 -1
- package/dist/public/node/hooks/postrun.js.map +1 -1
- package/dist/public/node/http.js +27 -22
- package/dist/public/node/http.js.map +1 -1
- package/dist/public/node/metadata.d.ts +12 -4
- package/dist/public/node/metadata.js +52 -4
- package/dist/public/node/metadata.js.map +1 -1
- package/dist/public/node/monorail.d.ts +8 -1
- package/dist/public/node/monorail.js +1 -1
- package/dist/public/node/monorail.js.map +1 -1
- package/dist/public/node/node-package-manager.d.ts +6 -0
- package/dist/public/node/node-package-manager.js +16 -2
- package/dist/public/node/node-package-manager.js.map +1 -1
- package/dist/public/node/testing/ui.d.ts +1 -1
- package/dist/public/node/testing/ui.js +1 -1
- package/dist/public/node/testing/ui.js.map +1 -1
- package/dist/public/node/ui.d.ts +1 -1
- package/dist/public/node/ui.js +63 -56
- package/dist/public/node/ui.js.map +1 -1
- package/dist/public/node/vendor/otel-js/export/InstantaneousMetricReader.d.ts +18 -0
- package/dist/public/node/vendor/otel-js/export/InstantaneousMetricReader.js +36 -0
- package/dist/public/node/vendor/otel-js/export/InstantaneousMetricReader.js.map +1 -0
- package/dist/public/node/vendor/otel-js/service/BaseOtelService/BaseOtelService.d.ts +46 -0
- package/dist/public/node/vendor/otel-js/service/BaseOtelService/BaseOtelService.js +112 -0
- package/dist/public/node/vendor/otel-js/service/BaseOtelService/BaseOtelService.js.map +1 -0
- package/dist/public/node/vendor/otel-js/service/DefaultOtelService/DefaultMeterProvider.d.ts +13 -0
- package/dist/public/node/vendor/otel-js/service/DefaultOtelService/DefaultMeterProvider.js +36 -0
- package/dist/public/node/vendor/otel-js/service/DefaultOtelService/DefaultMeterProvider.js.map +1 -0
- package/dist/public/node/vendor/otel-js/service/DefaultOtelService/DefaultOtelService.d.ts +24 -0
- package/dist/public/node/vendor/otel-js/service/DefaultOtelService/DefaultOtelService.js +33 -0
- package/dist/public/node/vendor/otel-js/service/DefaultOtelService/DefaultOtelService.js.map +1 -0
- package/dist/public/node/vendor/otel-js/service/types.d.ts +43 -0
- package/dist/public/node/vendor/otel-js/service/types.js +7 -0
- package/dist/public/node/vendor/otel-js/service/types.js.map +1 -0
- package/dist/public/node/vendor/otel-js/utils/throttle.d.ts +7 -0
- package/dist/public/node/vendor/otel-js/utils/throttle.js +42 -0
- package/dist/public/node/vendor/otel-js/utils/throttle.js.map +1 -0
- package/dist/public/node/vendor/otel-js/utils/validators.d.ts +1 -0
- package/dist/public/node/vendor/otel-js/utils/validators.js +11 -0
- package/dist/public/node/vendor/otel-js/utils/validators.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +25 -16
- package/assets/cli-ruby/RELEASING.md +0 -72
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { MetricAttributes } from '@opentelemetry/api';
|
|
2
|
+
import type { MeterProvider, ViewOptions } from '@opentelemetry/sdk-metrics';
|
|
3
|
+
import type { MetricDescriptor, MetricRecording, MetricsConfig, OnRecordCallback, OtelService, RecordMetricFunction } from '../types.js';
|
|
4
|
+
export interface BaseOtelServiceOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Service name is a unique name for an application/service.
|
|
7
|
+
*/
|
|
8
|
+
serviceName: string;
|
|
9
|
+
/**
|
|
10
|
+
* If this is set to true then the service name is prefixed to every metric.
|
|
11
|
+
*/
|
|
12
|
+
prefixMetric?: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Metrics to register on startup.
|
|
15
|
+
*/
|
|
16
|
+
metrics?: MetricsConfig;
|
|
17
|
+
/**
|
|
18
|
+
* Called when a metric is recorded. `addOnRecord` can also be used to add
|
|
19
|
+
* listeners anytime.
|
|
20
|
+
*/
|
|
21
|
+
onRecord?: OnRecordCallback;
|
|
22
|
+
/**
|
|
23
|
+
* Override the default meter provider.
|
|
24
|
+
*/
|
|
25
|
+
meterProvider?: MeterProvider;
|
|
26
|
+
}
|
|
27
|
+
export declare class BaseOtelService implements OtelService {
|
|
28
|
+
readonly serviceName: string;
|
|
29
|
+
readonly prefixMetric: boolean;
|
|
30
|
+
protected readonly meterProvider: MeterProvider;
|
|
31
|
+
protected readonly metrics: Map<string, RecordMetricFunction>;
|
|
32
|
+
protected readonly recordListeners: Set<OnRecordCallback>;
|
|
33
|
+
/**
|
|
34
|
+
* Bootstraps an Otel exporter which can send Otel metrics to a dedicated Shopify supported collector endpoint.
|
|
35
|
+
*/
|
|
36
|
+
constructor({ serviceName, prefixMetric, metrics, onRecord, meterProvider }: BaseOtelServiceOptions);
|
|
37
|
+
getMeterProvider(): MeterProvider;
|
|
38
|
+
addView(viewOptions: ViewOptions): void;
|
|
39
|
+
record(metricName: string, value: number, labels?: MetricAttributes): void;
|
|
40
|
+
registerMetric(metricName: string, { type, ...options }: MetricDescriptor): void;
|
|
41
|
+
register(metrics: MetricsConfig): void;
|
|
42
|
+
addOnRecord(onRecord: OnRecordCallback): () => void;
|
|
43
|
+
removeOnRecord(onRecord: OnRecordCallback): void;
|
|
44
|
+
shutdown(): Promise<void>;
|
|
45
|
+
protected notifyRecordListeners(metricName: string, initialValue: number, initialLabels: MetricAttributes): MetricRecording;
|
|
46
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { ExplicitBucketHistogramAggregation, View } from '@opentelemetry/sdk-metrics';
|
|
2
|
+
import { MetricInstrumentType } from '../types.js';
|
|
3
|
+
import { isValidMetricName } from '../../utils/validators.js';
|
|
4
|
+
const instrumentationScope = 'opentelemetry-js-shopify-web';
|
|
5
|
+
export class BaseOtelService {
|
|
6
|
+
/**
|
|
7
|
+
* Bootstraps an Otel exporter which can send Otel metrics to a dedicated Shopify supported collector endpoint.
|
|
8
|
+
*/
|
|
9
|
+
constructor({ serviceName, prefixMetric = false, metrics = {}, onRecord, meterProvider }) {
|
|
10
|
+
this.metrics = new Map();
|
|
11
|
+
this.recordListeners = new Set();
|
|
12
|
+
if (!serviceName) {
|
|
13
|
+
throw new Error('Service name is required.');
|
|
14
|
+
}
|
|
15
|
+
this.serviceName = serviceName;
|
|
16
|
+
this.prefixMetric = prefixMetric;
|
|
17
|
+
if (onRecord)
|
|
18
|
+
this.addOnRecord(onRecord);
|
|
19
|
+
if (!meterProvider) {
|
|
20
|
+
throw new Error('MeterProvider is required.');
|
|
21
|
+
}
|
|
22
|
+
this.meterProvider = meterProvider;
|
|
23
|
+
this.register(metrics);
|
|
24
|
+
}
|
|
25
|
+
getMeterProvider() {
|
|
26
|
+
return this.meterProvider;
|
|
27
|
+
}
|
|
28
|
+
addView(viewOptions) {
|
|
29
|
+
// The API to register view is not yet exposed. We need to use the private
|
|
30
|
+
// property to register a new view after the initial instantiation.
|
|
31
|
+
;
|
|
32
|
+
this.meterProvider._sharedState?.viewRegistry?.addView?.(new View(viewOptions));
|
|
33
|
+
}
|
|
34
|
+
record(metricName, value, labels) {
|
|
35
|
+
const recordMetric = this.metrics.get(metricName);
|
|
36
|
+
if (!recordMetric) {
|
|
37
|
+
throw new Error(`Service ${this.serviceName} has no metrics registered for name: ${metricName}. Can't record value for unknown metric.`);
|
|
38
|
+
}
|
|
39
|
+
recordMetric(value, labels);
|
|
40
|
+
}
|
|
41
|
+
registerMetric(metricName, { type, ...options }) {
|
|
42
|
+
if (this.metrics.has(metricName)) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const meter = this.meterProvider.getMeter(instrumentationScope);
|
|
46
|
+
const name = this.prefixMetric ? `${this.serviceName}_${metricName}` : metricName;
|
|
47
|
+
if (!isValidMetricName(name)) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const createInstrument = () => {
|
|
51
|
+
switch (type) {
|
|
52
|
+
case MetricInstrumentType.Counter:
|
|
53
|
+
return meter.createCounter(name, options);
|
|
54
|
+
case MetricInstrumentType.UpDownCounter:
|
|
55
|
+
return meter.createUpDownCounter(name, options);
|
|
56
|
+
case MetricInstrumentType.Histogram: {
|
|
57
|
+
if ('boundaries' in options) {
|
|
58
|
+
this.addView({
|
|
59
|
+
instrumentName: name,
|
|
60
|
+
aggregation: new ExplicitBucketHistogramAggregation(options.boundaries, true),
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
return meter.createHistogram(name, options);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
// Lazy instantiate the instrument so we don't create it if we don't need to
|
|
68
|
+
this.metrics.set(metricName, (firstValue, firstLabels) => {
|
|
69
|
+
const instrument = createInstrument();
|
|
70
|
+
const record = (value, labels) => {
|
|
71
|
+
const [finalValue, finalLabels] = this.notifyRecordListeners(metricName, value,
|
|
72
|
+
// ensures an new object is created so we don't mutate the original
|
|
73
|
+
{ ...labels });
|
|
74
|
+
if ('record' in instrument) {
|
|
75
|
+
instrument.record(finalValue, finalLabels);
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
instrument.add(finalValue, finalLabels);
|
|
79
|
+
}
|
|
80
|
+
// We flush metrics after every record - we do not await as we fire & forget.
|
|
81
|
+
this.meterProvider.forceFlush({});
|
|
82
|
+
};
|
|
83
|
+
record(firstValue, firstLabels);
|
|
84
|
+
this.metrics.set(metricName, record);
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
register(metrics) {
|
|
88
|
+
Object.entries(metrics).forEach(([metricName, options]) => {
|
|
89
|
+
this.registerMetric(metricName, options);
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
addOnRecord(onRecord) {
|
|
93
|
+
this.recordListeners.add(onRecord);
|
|
94
|
+
return () => {
|
|
95
|
+
this.recordListeners.delete(onRecord);
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
removeOnRecord(onRecord) {
|
|
99
|
+
this.recordListeners.delete(onRecord);
|
|
100
|
+
}
|
|
101
|
+
shutdown() {
|
|
102
|
+
this.metrics.clear();
|
|
103
|
+
this.recordListeners.clear();
|
|
104
|
+
return this.meterProvider.shutdown();
|
|
105
|
+
}
|
|
106
|
+
notifyRecordListeners(metricName, initialValue, initialLabels) {
|
|
107
|
+
return Array.from(this.recordListeners).reduce((recordArgs, listener) => {
|
|
108
|
+
return listener(metricName, ...recordArgs) || recordArgs;
|
|
109
|
+
}, [initialValue, initialLabels]);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
//# sourceMappingURL=BaseOtelService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BaseOtelService.js","sourceRoot":"","sources":["../../../../../../../src/public/node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AC,eAAe,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;QACvC,CAAC,CAAA;IACH,CAAC;IAED,cAAc,CAAC,QAA0B;QACvC,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;IACvC,CAAC;IAED,QAAQ;QACN,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAA;QACpB,IAAI,CAAC,eAAe,CAAC,KAAK,EAAE,CAAA;QAC5B,OAAO,IAAI,CAAC,aAAa,CAAC,QAAQ,EAAE,CAAA;IACtC,CAAC;IAES,qBAAqB,CAAC,UAAkB,EAAE,YAAoB,EAAE,aAA+B;QACvG,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,MAAM,CAC5C,CAAC,UAAU,EAAE,QAAQ,EAAE,EAAE;YACvB,OAAO,QAAQ,CAAC,UAAU,EAAE,GAAG,UAAU,CAAC,IAAI,UAAU,CAAA;QAC1D,CAAC,EACD,CAAC,YAAY,EAAE,aAAa,CAAC,CAC9B,CAAA;IACH,CAAC;CACF","sourcesContent":["import type {MetricAttributes} from '@opentelemetry/api'\nimport type {MeterProvider, ViewOptions} from '@opentelemetry/sdk-metrics'\nimport {ExplicitBucketHistogramAggregation, View} from '@opentelemetry/sdk-metrics'\n\nimport type {\n MetricDescriptor,\n MetricRecording,\n MetricsConfig,\n OnRecordCallback,\n OtelService,\n RecordMetricFunction,\n} from '../types.js'\nimport {MetricInstrumentType} from '../types.js'\nimport {isValidMetricName} from '../../utils/validators.js'\n\nconst instrumentationScope = 'opentelemetry-js-shopify-web'\n\nexport interface BaseOtelServiceOptions {\n /**\n * Service name is a unique name for an application/service.\n */\n serviceName: string\n\n /**\n * If this is set to true then the service name is prefixed to every metric.\n */\n prefixMetric?: boolean\n\n /**\n * Metrics to register on startup.\n */\n metrics?: MetricsConfig\n\n /**\n * Called when a metric is recorded. `addOnRecord` can also be used to add\n * listeners anytime.\n */\n onRecord?: OnRecordCallback\n\n /**\n * Override the default meter provider.\n */\n meterProvider?: MeterProvider\n}\n\nexport class BaseOtelService implements OtelService {\n readonly serviceName: string\n readonly prefixMetric: boolean\n\n protected readonly meterProvider: MeterProvider\n protected readonly metrics: Map<string, RecordMetricFunction> = new Map()\n protected readonly recordListeners = new Set<OnRecordCallback>()\n\n /**\n * Bootstraps an Otel exporter which can send Otel metrics to a dedicated Shopify supported collector endpoint.\n */\n constructor({serviceName, prefixMetric = false, metrics = {}, onRecord, meterProvider}: BaseOtelServiceOptions) {\n if (!serviceName) {\n throw new Error('Service name is required.')\n }\n this.serviceName = serviceName\n\n this.prefixMetric = prefixMetric\n if (onRecord) this.addOnRecord(onRecord)\n\n if (!meterProvider) {\n throw new Error('MeterProvider is required.')\n }\n this.meterProvider = meterProvider\n\n this.register(metrics)\n }\n\n getMeterProvider(): MeterProvider {\n return this.meterProvider\n }\n\n addView(viewOptions: ViewOptions) {\n // The API to register view is not yet exposed. We need to use the private\n // property to register a new view after the initial instantiation.\n ;(this.meterProvider as any)._sharedState?.viewRegistry?.addView?.(new View(viewOptions))\n }\n\n record(metricName: string, value: number, labels?: MetricAttributes): void {\n const recordMetric = this.metrics.get(metricName)\n if (!recordMetric) {\n throw new Error(\n `Service ${this.serviceName} has no metrics registered for name: ${metricName}. Can't record value for unknown metric.`,\n )\n }\n recordMetric(value, labels)\n }\n\n registerMetric(metricName: string, {type, ...options}: MetricDescriptor): void {\n if (this.metrics.has(metricName)) {\n return\n }\n const meter = this.meterProvider.getMeter(instrumentationScope)\n const name = this.prefixMetric ? `${this.serviceName}_${metricName}` : metricName\n\n if (!isValidMetricName(name)) {\n return\n }\n\n const createInstrument = () => {\n switch (type) {\n case MetricInstrumentType.Counter:\n return meter.createCounter(name, options)\n case MetricInstrumentType.UpDownCounter:\n return meter.createUpDownCounter(name, options)\n case MetricInstrumentType.Histogram: {\n if ('boundaries' in options) {\n this.addView({\n instrumentName: name,\n aggregation: new ExplicitBucketHistogramAggregation(options.boundaries, true),\n })\n }\n return meter.createHistogram(name, options)\n }\n }\n }\n\n // Lazy instantiate the instrument so we don't create it if we don't need to\n this.metrics.set(metricName, (firstValue: number, firstLabels?: MetricAttributes) => {\n const instrument = createInstrument()\n const record = (value: number, labels?: MetricAttributes) => {\n const [finalValue, finalLabels] = this.notifyRecordListeners(\n metricName,\n value,\n // ensures an new object is created so we don't mutate the original\n {...labels},\n )\n if ('record' in instrument) {\n instrument.record(finalValue, finalLabels)\n } else {\n instrument.add(finalValue, finalLabels)\n }\n // We flush metrics after every record - we do not await as we fire & forget.\n this.meterProvider.forceFlush({})\n }\n record(firstValue, firstLabels)\n this.metrics.set(metricName, record)\n })\n }\n\n register(metrics: MetricsConfig) {\n Object.entries(metrics).forEach(([metricName, options]) => {\n this.registerMetric(metricName, options)\n })\n }\n\n addOnRecord(onRecord: OnRecordCallback): () => void {\n this.recordListeners.add(onRecord)\n return () => {\n this.recordListeners.delete(onRecord)\n }\n }\n\n removeOnRecord(onRecord: OnRecordCallback): void {\n this.recordListeners.delete(onRecord)\n }\n\n shutdown(): Promise<void> {\n this.metrics.clear()\n this.recordListeners.clear()\n return this.meterProvider.shutdown()\n }\n\n protected notifyRecordListeners(metricName: string, initialValue: number, initialLabels: MetricAttributes) {\n return Array.from(this.recordListeners).reduce<MetricRecording>(\n (recordArgs, listener) => {\n return listener(metricName, ...recordArgs) || recordArgs\n },\n [initialValue, initialLabels],\n )\n }\n}\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { MeterProvider } from '@opentelemetry/sdk-metrics';
|
|
2
|
+
export type Environment = 'production' | 'staging' | 'local';
|
|
3
|
+
interface DefaultMeterProviderOptions {
|
|
4
|
+
serviceName: string;
|
|
5
|
+
env: string;
|
|
6
|
+
throttleLimit: number;
|
|
7
|
+
useXhr: boolean;
|
|
8
|
+
otelEndpoint: string;
|
|
9
|
+
}
|
|
10
|
+
export declare class DefaultMeterProvider extends MeterProvider {
|
|
11
|
+
constructor({ serviceName, env, throttleLimit, useXhr, otelEndpoint }: DefaultMeterProviderOptions);
|
|
12
|
+
}
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { InstantaneousMetricReader } from '../../export/InstantaneousMetricReader.js';
|
|
2
|
+
import { OTLPMetricExporter } from '@opentelemetry/exporter-metrics-otlp-http';
|
|
3
|
+
import { Resource } from '@opentelemetry/resources';
|
|
4
|
+
import { AggregationTemporality, ConsoleMetricExporter, MeterProvider } from '@opentelemetry/sdk-metrics';
|
|
5
|
+
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
|
|
6
|
+
export class DefaultMeterProvider extends MeterProvider {
|
|
7
|
+
constructor({ serviceName, env, throttleLimit, useXhr, otelEndpoint }) {
|
|
8
|
+
super({
|
|
9
|
+
resource: new Resource({
|
|
10
|
+
[SemanticResourceAttributes.SERVICE_NAME]: serviceName,
|
|
11
|
+
}),
|
|
12
|
+
});
|
|
13
|
+
const opts = {
|
|
14
|
+
// url: OTEL_ENDPOINTS[env as Environment] || OTEL_ENDPOINTS.local,
|
|
15
|
+
// CLI addition
|
|
16
|
+
url: otelEndpoint,
|
|
17
|
+
temporalityPreference: AggregationTemporality.DELTA,
|
|
18
|
+
};
|
|
19
|
+
if (useXhr) {
|
|
20
|
+
opts.headers = {};
|
|
21
|
+
}
|
|
22
|
+
const exporter = new OTLPMetricExporter(opts);
|
|
23
|
+
this.addMetricReader(new InstantaneousMetricReader({
|
|
24
|
+
exporter,
|
|
25
|
+
throttleLimit,
|
|
26
|
+
}));
|
|
27
|
+
// Add a console exporter to see what we are sending in dev environments
|
|
28
|
+
if (env === 'dev') {
|
|
29
|
+
this.addMetricReader(new InstantaneousMetricReader({
|
|
30
|
+
exporter: new ConsoleMetricExporter(),
|
|
31
|
+
throttleLimit,
|
|
32
|
+
}));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=DefaultMeterProvider.js.map
|
package/dist/public/node/vendor/otel-js/service/DefaultOtelService/DefaultMeterProvider.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DefaultMeterProvider.js","sourceRoot":"","sources":["../../../../../../../src/public/node/vendor/otel-js/service/DefaultOtelService/DefaultMeterProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,yBAAyB,EAAC,MAAM,2CAA2C,CAAA;AACnF,OAAO,EAAC,kBAAkB,EAA4B,MAAM,2CAA2C,CAAA;AACvG,OAAO,EAAC,QAAQ,EAAC,MAAM,0BAA0B,CAAA;AACjD,OAAO,EAAC,sBAAsB,EAAE,qBAAqB,EAAE,aAAa,EAAC,MAAM,4BAA4B,CAAA;AACvG,OAAO,EAAC,0BAA0B,EAAC,MAAM,qCAAqC,CAAA;AAa9E,MAAM,OAAO,oBAAqB,SAAQ,aAAa;IACrD,YAAY,EAAC,WAAW,EAAE,GAAG,EAAE,aAAa,EAAE,MAAM,EAAE,YAAY,EAA8B;QAC9F,KAAK,CAAC;YACJ,QAAQ,EAAE,IAAI,QAAQ,CAAC;gBACrB,CAAC,0BAA0B,CAAC,YAAY,CAAC,EAAE,WAAW;aACvD,CAAC;SACH,CAAC,CAAA;QAEF,MAAM,IAAI,GAA8B;YACtC,mEAAmE;YACnE,eAAe;YACf,GAAG,EAAE,YAAY;YACjB,qBAAqB,EAAE,sBAAsB,CAAC,KAAK;SACpD,CAAA;QAED,IAAI,MAAM,EAAE;YACV,IAAI,CAAC,OAAO,GAAG,EAAE,CAAA;SAClB;QAED,MAAM,QAAQ,GAAG,IAAI,kBAAkB,CAAC,IAAI,CAAC,CAAA;QAE7C,IAAI,CAAC,eAAe,CAClB,IAAI,yBAAyB,CAAC;YAC5B,QAAQ;YACR,aAAa;SACd,CAAC,CACH,CAAA;QAED,wEAAwE;QACxE,IAAI,GAAG,KAAK,KAAK,EAAE;YACjB,IAAI,CAAC,eAAe,CAClB,IAAI,yBAAyB,CAAC;gBAC5B,QAAQ,EAAE,IAAI,qBAAqB,EAAE;gBACrC,aAAa;aACd,CAAC,CACH,CAAA;SACF;IACH,CAAC;CACF","sourcesContent":["import {InstantaneousMetricReader} from '../../export/InstantaneousMetricReader.js'\nimport {OTLPMetricExporter, OTLPMetricExporterOptions} from '@opentelemetry/exporter-metrics-otlp-http'\nimport {Resource} from '@opentelemetry/resources'\nimport {AggregationTemporality, ConsoleMetricExporter, MeterProvider} from '@opentelemetry/sdk-metrics'\nimport {SemanticResourceAttributes} from '@opentelemetry/semantic-conventions'\n\nexport type Environment = 'production' | 'staging' | 'local'\n\ninterface DefaultMeterProviderOptions {\n serviceName: string\n env: string\n throttleLimit: number\n useXhr: boolean\n // CLI addition\n otelEndpoint: string\n}\n\nexport class DefaultMeterProvider extends MeterProvider {\n constructor({serviceName, env, throttleLimit, useXhr, otelEndpoint}: DefaultMeterProviderOptions) {\n super({\n resource: new Resource({\n [SemanticResourceAttributes.SERVICE_NAME]: serviceName,\n }),\n })\n\n const opts: OTLPMetricExporterOptions = {\n // url: OTEL_ENDPOINTS[env as Environment] || OTEL_ENDPOINTS.local,\n // CLI addition\n url: otelEndpoint,\n temporalityPreference: AggregationTemporality.DELTA,\n }\n\n if (useXhr) {\n opts.headers = {}\n }\n\n const exporter = new OTLPMetricExporter(opts)\n\n this.addMetricReader(\n new InstantaneousMetricReader({\n exporter,\n throttleLimit,\n }),\n )\n\n // Add a console exporter to see what we are sending in dev environments\n if (env === 'dev') {\n this.addMetricReader(\n new InstantaneousMetricReader({\n exporter: new ConsoleMetricExporter(),\n throttleLimit,\n }),\n )\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { BaseOtelService } from '../BaseOtelService/BaseOtelService.js';
|
|
2
|
+
import type { BaseOtelServiceOptions } from '../BaseOtelService/BaseOtelService.js';
|
|
3
|
+
export interface DefaultOtelServiceOptions extends BaseOtelServiceOptions {
|
|
4
|
+
/**
|
|
5
|
+
* What environment is being deployed (production, staging)
|
|
6
|
+
*/
|
|
7
|
+
env?: string;
|
|
8
|
+
/**
|
|
9
|
+
* How much the export should be throttled in milliseconds.
|
|
10
|
+
*/
|
|
11
|
+
throttleLimit?: number;
|
|
12
|
+
/**
|
|
13
|
+
* Determines whether to send metrics via XHR or beacon. Defaults to false.
|
|
14
|
+
*/
|
|
15
|
+
useXhr?: boolean;
|
|
16
|
+
otelEndpoint: string;
|
|
17
|
+
}
|
|
18
|
+
export declare class DefaultOtelService extends BaseOtelService {
|
|
19
|
+
/**
|
|
20
|
+
* Bootstraps an Otel exporter which can send Otel metrics to a dedicated Shopify supported collector endpoint.
|
|
21
|
+
*/
|
|
22
|
+
constructor({ throttleLimit, env, serviceName, prefixMetric, metrics, onRecord, meterProvider, useXhr, otelEndpoint, }: DefaultOtelServiceOptions);
|
|
23
|
+
shutdown(): Promise<void>;
|
|
24
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { DefaultMeterProvider } from './DefaultMeterProvider.js';
|
|
2
|
+
import { BaseOtelService } from '../BaseOtelService/BaseOtelService.js';
|
|
3
|
+
import { diag, DiagConsoleLogger, DiagLogLevel } from '@opentelemetry/api';
|
|
4
|
+
export class DefaultOtelService extends BaseOtelService {
|
|
5
|
+
/**
|
|
6
|
+
* Bootstraps an Otel exporter which can send Otel metrics to a dedicated Shopify supported collector endpoint.
|
|
7
|
+
*/
|
|
8
|
+
constructor({ throttleLimit = 5000, env = 'local', serviceName, prefixMetric = false, metrics = {}, onRecord, meterProvider, useXhr = false,
|
|
9
|
+
// CLI addition
|
|
10
|
+
otelEndpoint, }) {
|
|
11
|
+
diag.setLogger(new DiagConsoleLogger(), ['production', 'staging'].includes(env) ? DiagLogLevel.ERROR : DiagLogLevel.INFO);
|
|
12
|
+
super({
|
|
13
|
+
serviceName,
|
|
14
|
+
meterProvider: meterProvider ??
|
|
15
|
+
new DefaultMeterProvider({
|
|
16
|
+
serviceName,
|
|
17
|
+
env,
|
|
18
|
+
throttleLimit,
|
|
19
|
+
useXhr,
|
|
20
|
+
// CLI addition
|
|
21
|
+
otelEndpoint,
|
|
22
|
+
}),
|
|
23
|
+
prefixMetric,
|
|
24
|
+
metrics,
|
|
25
|
+
onRecord,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
shutdown() {
|
|
29
|
+
diag.disable();
|
|
30
|
+
return super.shutdown();
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=DefaultOtelService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DefaultOtelService.js","sourceRoot":"","sources":["../../../../../../../src/public/node/vendor/otel-js/service/DefaultOtelService/DefaultOtelService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,oBAAoB,EAAC,MAAM,2BAA2B,CAAA;AAC9D,OAAO,EAAC,eAAe,EAAC,MAAM,uCAAuC,CAAA;AACrE,OAAO,EAAC,IAAI,EAAE,iBAAiB,EAAE,YAAY,EAAC,MAAM,oBAAoB,CAAA;AAsBxE,MAAM,OAAO,kBAAmB,SAAQ,eAAe;IACrD;;OAEG;IACH,YAAY,EACV,aAAa,GAAG,IAAI,EACpB,GAAG,GAAG,OAAO,EACb,WAAW,EACX,YAAY,GAAG,KAAK,EACpB,OAAO,GAAG,EAAE,EACZ,QAAQ,EACR,aAAa,EACb,MAAM,GAAG,KAAK;IACd,eAAe;IACf,YAAY,GACc;QAC1B,IAAI,CAAC,SAAS,CACZ,IAAI,iBAAiB,EAAE,EACvB,CAAC,YAAY,EAAE,SAAS,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,YAAY,CAAC,IAAI,CACjF,CAAA;QAED,KAAK,CAAC;YACJ,WAAW;YACX,aAAa,EACX,aAAa;gBACb,IAAI,oBAAoB,CAAC;oBACvB,WAAW;oBACX,GAAG;oBACH,aAAa;oBACb,MAAM;oBACN,eAAe;oBACf,YAAY;iBACb,CAAC;YACJ,YAAY;YACZ,OAAO;YACP,QAAQ;SACT,CAAC,CAAA;IACJ,CAAC;IAEQ,QAAQ;QACf,IAAI,CAAC,OAAO,EAAE,CAAA;QACd,OAAO,KAAK,CAAC,QAAQ,EAAE,CAAA;IACzB,CAAC;CACF","sourcesContent":["import {DefaultMeterProvider} from './DefaultMeterProvider.js'\nimport {BaseOtelService} from '../BaseOtelService/BaseOtelService.js'\nimport {diag, DiagConsoleLogger, DiagLogLevel} from '@opentelemetry/api'\n\nimport type {BaseOtelServiceOptions} from '../BaseOtelService/BaseOtelService.js'\n\nexport interface DefaultOtelServiceOptions extends BaseOtelServiceOptions {\n /**\n * What environment is being deployed (production, staging)\n */\n env?: string\n /**\n * How much the export should be throttled in milliseconds.\n */\n throttleLimit?: number\n /**\n * Determines whether to send metrics via XHR or beacon. Defaults to false.\n */\n useXhr?: boolean\n\n // CLI addition\n otelEndpoint: string\n}\n\nexport class DefaultOtelService extends BaseOtelService {\n /**\n * Bootstraps an Otel exporter which can send Otel metrics to a dedicated Shopify supported collector endpoint.\n */\n constructor({\n throttleLimit = 5000,\n env = 'local',\n serviceName,\n prefixMetric = false,\n metrics = {},\n onRecord,\n meterProvider,\n useXhr = false,\n // CLI addition\n otelEndpoint,\n }: DefaultOtelServiceOptions) {\n diag.setLogger(\n new DiagConsoleLogger(),\n ['production', 'staging'].includes(env) ? DiagLogLevel.ERROR : DiagLogLevel.INFO,\n )\n\n super({\n serviceName,\n meterProvider:\n meterProvider ??\n new DefaultMeterProvider({\n serviceName,\n env,\n throttleLimit,\n useXhr,\n // CLI addition\n otelEndpoint,\n }),\n prefixMetric,\n metrics,\n onRecord,\n })\n }\n\n override shutdown(): Promise<void> {\n diag.disable()\n return super.shutdown()\n }\n}\n"]}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { Counter, Histogram, MeterProvider, MetricAttributes, MetricOptions, UpDownCounter } from '@opentelemetry/api';
|
|
2
|
+
import type { ViewOptions } from '@opentelemetry/sdk-metrics';
|
|
3
|
+
export type CustomMetricLabels<TLabels extends {
|
|
4
|
+
[key in TKeys]: MetricAttributes;
|
|
5
|
+
}, TKeys extends string = keyof TLabels & string> = {
|
|
6
|
+
[P in TKeys]: TLabels[P] extends MetricAttributes ? TLabels[P] : never;
|
|
7
|
+
};
|
|
8
|
+
export type MetricRecording<TAttributes extends MetricAttributes = any> = [value: number, labels?: TAttributes];
|
|
9
|
+
export type RecordMetricFunction<TAttributes extends MetricAttributes = any> = (...args: MetricRecording<TAttributes>) => void;
|
|
10
|
+
export type OnRecordCallback<TAttributes extends MetricAttributes = any> = (metricName: string, ...args: MetricRecording<TAttributes>) => MetricRecording<TAttributes> | void;
|
|
11
|
+
export type MetricInstrument = Histogram | Counter | UpDownCounter;
|
|
12
|
+
export declare enum MetricInstrumentType {
|
|
13
|
+
Histogram = "Histogram",
|
|
14
|
+
Counter = "Counter",
|
|
15
|
+
UpDownCounter = "UpDownCounter"
|
|
16
|
+
}
|
|
17
|
+
export type MetricDescriptor = MetricOptions & ({
|
|
18
|
+
type: MetricInstrumentType.Histogram;
|
|
19
|
+
/**
|
|
20
|
+
* Boundaries are required for Histograms.
|
|
21
|
+
*/
|
|
22
|
+
boundaries: number[];
|
|
23
|
+
} | {
|
|
24
|
+
type: MetricInstrumentType.Counter | MetricInstrumentType.UpDownCounter;
|
|
25
|
+
});
|
|
26
|
+
export interface MetricsConfig {
|
|
27
|
+
[key: string]: MetricDescriptor;
|
|
28
|
+
}
|
|
29
|
+
export interface OtelService {
|
|
30
|
+
readonly serviceName: string;
|
|
31
|
+
getMeterProvider(): MeterProvider;
|
|
32
|
+
addView(viewOptions: ViewOptions): void;
|
|
33
|
+
record<TAttributes extends MetricAttributes = any>(...args: Parameters<OnRecordCallback<TAttributes>>): void;
|
|
34
|
+
/**
|
|
35
|
+
* `onRecord` callback is called when a metric is recorded.
|
|
36
|
+
* Returns a function to unsubscribe.
|
|
37
|
+
*/
|
|
38
|
+
addOnRecord(onRecord: OnRecordCallback): () => void;
|
|
39
|
+
removeOnRecord(onRecord: OnRecordCallback): void;
|
|
40
|
+
registerMetric(metricName: string, options: MetricDescriptor): void;
|
|
41
|
+
register(metrics: MetricsConfig): void;
|
|
42
|
+
shutdown(): Promise<void>;
|
|
43
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export var MetricInstrumentType;
|
|
2
|
+
(function (MetricInstrumentType) {
|
|
3
|
+
MetricInstrumentType["Histogram"] = "Histogram";
|
|
4
|
+
MetricInstrumentType["Counter"] = "Counter";
|
|
5
|
+
MetricInstrumentType["UpDownCounter"] = "UpDownCounter";
|
|
6
|
+
})(MetricInstrumentType || (MetricInstrumentType = {}));
|
|
7
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../../src/public/node/vendor/otel-js/service/types.ts"],"names":[],"mappings":"AA8BA,MAAM,CAAN,IAAY,oBAIX;AAJD,WAAY,oBAAoB;IAC9B,+CAAuB,CAAA;IACvB,2CAAmB,CAAA;IACnB,uDAA+B,CAAA;AACjC,CAAC,EAJW,oBAAoB,KAApB,oBAAoB,QAI/B","sourcesContent":["import type {\n Counter,\n Histogram,\n MeterProvider,\n MetricAttributes,\n MetricOptions,\n UpDownCounter,\n} from '@opentelemetry/api'\nimport type {ViewOptions} from '@opentelemetry/sdk-metrics'\n\nexport type CustomMetricLabels<\n TLabels extends {[key in TKeys]: MetricAttributes},\n TKeys extends string = keyof TLabels & string,\n> = {\n [P in TKeys]: TLabels[P] extends MetricAttributes ? TLabels[P] : never\n}\n\nexport type MetricRecording<TAttributes extends MetricAttributes = any> = [value: number, labels?: TAttributes]\n\nexport type RecordMetricFunction<TAttributes extends MetricAttributes = any> = (\n ...args: MetricRecording<TAttributes>\n) => void\n\nexport type OnRecordCallback<TAttributes extends MetricAttributes = any> = (\n metricName: string,\n ...args: MetricRecording<TAttributes>\n) => MetricRecording<TAttributes> | void\n\nexport type MetricInstrument = Histogram | Counter | UpDownCounter\n\nexport enum MetricInstrumentType {\n Histogram = 'Histogram',\n Counter = 'Counter',\n UpDownCounter = 'UpDownCounter',\n}\n\nexport type MetricDescriptor = MetricOptions &\n (\n | {\n type: MetricInstrumentType.Histogram\n /**\n * Boundaries are required for Histograms.\n */\n boundaries: number[]\n }\n | {\n type: MetricInstrumentType.Counter | MetricInstrumentType.UpDownCounter\n }\n )\n\nexport interface MetricsConfig {\n [key: string]: MetricDescriptor\n}\n\nexport interface OtelService {\n readonly serviceName: string\n\n getMeterProvider(): MeterProvider\n\n addView(viewOptions: ViewOptions): void\n\n record<TAttributes extends MetricAttributes = any>(...args: Parameters<OnRecordCallback<TAttributes>>): void\n\n /**\n * `onRecord` callback is called when a metric is recorded.\n * Returns a function to unsubscribe.\n */\n addOnRecord(onRecord: OnRecordCallback): () => void\n\n removeOnRecord(onRecord: OnRecordCallback): void\n\n registerMetric(metricName: string, options: MetricDescriptor): void\n\n register(metrics: MetricsConfig): void\n\n shutdown(): Promise<void>\n}\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
type ThrottledFunction<T extends (...args: any) => any> = (...args: Parameters<T>) => ReturnType<T>;
|
|
2
|
+
interface ThrottleOptions {
|
|
3
|
+
leading?: boolean;
|
|
4
|
+
trailing?: boolean;
|
|
5
|
+
}
|
|
6
|
+
export declare function throttle<T extends (...args: any) => any>(func: T, wait: number, { leading, trailing }?: ThrottleOptions): ThrottledFunction<T>;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export function throttle(func, wait, { leading = true, trailing = true } = {}) {
|
|
2
|
+
let lastArgs;
|
|
3
|
+
let result;
|
|
4
|
+
let context;
|
|
5
|
+
let timeout = null;
|
|
6
|
+
let previous = 0;
|
|
7
|
+
function later() {
|
|
8
|
+
previous = leading === false ? 0 : Date.now();
|
|
9
|
+
timeout = null;
|
|
10
|
+
if (lastArgs) {
|
|
11
|
+
result = func.apply(context, lastArgs);
|
|
12
|
+
}
|
|
13
|
+
context = null;
|
|
14
|
+
lastArgs = null;
|
|
15
|
+
}
|
|
16
|
+
return function (...args) {
|
|
17
|
+
const now = Date.now();
|
|
18
|
+
if (!previous && leading === false)
|
|
19
|
+
previous = now;
|
|
20
|
+
const remaining = wait - (now - previous);
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias, consistent-this
|
|
22
|
+
context = this;
|
|
23
|
+
lastArgs = args;
|
|
24
|
+
if (remaining <= 0 || remaining > wait) {
|
|
25
|
+
if (timeout) {
|
|
26
|
+
clearTimeout(timeout);
|
|
27
|
+
timeout = null;
|
|
28
|
+
}
|
|
29
|
+
previous = now;
|
|
30
|
+
if (lastArgs) {
|
|
31
|
+
result = func.apply(context, lastArgs);
|
|
32
|
+
}
|
|
33
|
+
context = null;
|
|
34
|
+
lastArgs = null;
|
|
35
|
+
}
|
|
36
|
+
else if (!timeout && trailing !== false) {
|
|
37
|
+
timeout = setTimeout(later, remaining);
|
|
38
|
+
}
|
|
39
|
+
return result;
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=throttle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"throttle.js","sourceRoot":"","sources":["../../../../../../src/public/node/vendor/otel-js/utils/throttle.ts"],"names":[],"mappings":"AAOA,MAAM,UAAU,QAAQ,CACtB,IAAO,EACP,IAAY,EACZ,EAAC,OAAO,GAAG,IAAI,EAAE,QAAQ,GAAG,IAAI,KAAqB,EAAE;IAEvD,IAAI,QAA8B,CAAA;IAClC,IAAI,MAAqB,CAAA;IACzB,IAAI,OAAY,CAAA;IAChB,IAAI,OAAO,GAAyC,IAAI,CAAA;IACxD,IAAI,QAAQ,GAAG,CAAC,CAAA;IAEhB,SAAS,KAAK;QACZ,QAAQ,GAAG,OAAO,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAA;QAC7C,OAAO,GAAG,IAAI,CAAA;QACd,IAAI,QAAQ,EAAE;YACZ,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAA;SACvC;QACD,OAAO,GAAG,IAAI,CAAA;QACd,QAAQ,GAAG,IAAI,CAAA;IACjB,CAAC;IAED,OAAO,UAAqB,GAAG,IAAmB;QAChD,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;QACtB,IAAI,CAAC,QAAQ,IAAI,OAAO,KAAK,KAAK;YAAE,QAAQ,GAAG,GAAG,CAAA;QAElD,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,GAAG,GAAG,QAAQ,CAAC,CAAA;QACzC,6EAA6E;QAC7E,OAAO,GAAG,IAAI,CAAA;QACd,QAAQ,GAAG,IAAI,CAAA;QACf,IAAI,SAAS,IAAI,CAAC,IAAI,SAAS,GAAG,IAAI,EAAE;YACtC,IAAI,OAAO,EAAE;gBACX,YAAY,CAAC,OAAO,CAAC,CAAA;gBACrB,OAAO,GAAG,IAAI,CAAA;aACf;YACD,QAAQ,GAAG,GAAG,CAAA;YACd,IAAI,QAAQ,EAAE;gBACZ,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAA;aACvC;YACD,OAAO,GAAG,IAAI,CAAA;YACd,QAAQ,GAAG,IAAI,CAAA;SAChB;aAAM,IAAI,CAAC,OAAO,IAAI,QAAQ,KAAK,KAAK,EAAE;YACzC,OAAO,GAAG,UAAU,CAAC,KAAK,EAAE,SAAS,CAAC,CAAA;SACvC;QACD,OAAO,MAAM,CAAA;IACf,CAAC,CAAA;AACH,CAAC","sourcesContent":["type ThrottledFunction<T extends (...args: any) => any> = (...args: Parameters<T>) => ReturnType<T>\n\ninterface ThrottleOptions {\n leading?: boolean\n trailing?: boolean\n}\n\nexport function throttle<T extends (...args: any) => any>(\n func: T,\n wait: number,\n {leading = true, trailing = true}: ThrottleOptions = {},\n): ThrottledFunction<T> {\n let lastArgs: Parameters<T> | null\n let result: ReturnType<T>\n let context: any\n let timeout: ReturnType<typeof setTimeout> | null = null\n let previous = 0\n\n function later() {\n previous = leading === false ? 0 : Date.now()\n timeout = null\n if (lastArgs) {\n result = func.apply(context, lastArgs)\n }\n context = null\n lastArgs = null\n }\n\n return function (this: any, ...args: Parameters<T>): ReturnType<T> {\n const now = Date.now()\n if (!previous && leading === false) previous = now\n\n const remaining = wait - (now - previous)\n // eslint-disable-next-line @typescript-eslint/no-this-alias, consistent-this\n context = this\n lastArgs = args\n if (remaining <= 0 || remaining > wait) {\n if (timeout) {\n clearTimeout(timeout)\n timeout = null\n }\n previous = now\n if (lastArgs) {\n result = func.apply(context, lastArgs)\n }\n context = null\n lastArgs = null\n } else if (!timeout && trailing !== false) {\n timeout = setTimeout(later, remaining)\n }\n return result\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isValidMetricName(value: string): boolean;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { diag } from '@opentelemetry/api';
|
|
2
|
+
const validMetricRegex = new RegExp('[^a-zA-Z_][^a-zA-Z0-9_]*');
|
|
3
|
+
export function isValidMetricName(value) {
|
|
4
|
+
if (validMetricRegex.test(value)) {
|
|
5
|
+
diag.warn(`Metric name ${value} contains invalid characters and will be dropped.
|
|
6
|
+
Service Names and metric names must conform to the following regex %c[a-zA-Z_][a-zA-Z0-9_]*`, 'color:red');
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=validators.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validators.js","sourceRoot":"","sources":["../../../../../../src/public/node/vendor/otel-js/utils/validators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,IAAI,EAAC,MAAM,oBAAoB,CAAA;AAEvC,MAAM,gBAAgB,GAAG,IAAI,MAAM,CAAC,0BAA0B,CAAC,CAAA;AAE/D,MAAM,UAAU,iBAAiB,CAAC,KAAa;IAC7C,IAAI,gBAAgB,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE;QAChC,IAAI,CAAC,IAAI,CACP,eAAe,KAAK;gGACsE,EAC1F,WAAW,CACZ,CAAA;QACD,OAAO,KAAK,CAAA;KACb;IAED,OAAO,IAAI,CAAA;AACb,CAAC","sourcesContent":["import {diag} from '@opentelemetry/api'\n\nconst validMetricRegex = new RegExp('[^a-zA-Z_][^a-zA-Z0-9_]*')\n\nexport function isValidMetricName(value: string): boolean {\n if (validMetricRegex.test(value)) {\n diag.warn(\n `Metric name ${value} contains invalid characters and will be dropped.\n Service Names and metric names must conform to the following regex %c[a-zA-Z_][a-zA-Z0-9_]*`,\n 'color:red',\n )\n return false\n }\n\n return true\n}\n"]}
|