Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenTelemetry Mode support #32

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions src/OpenAPM.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ import {
} from '@opentelemetry/api';
import {
MeterProvider,
PeriodicExportingMetricReader,
ConsoleMetricExporter
PeriodicExportingMetricReader
} from '@opentelemetry/sdk-metrics';
import {
OTLPMetricExporter,
OTLPMetricExporterOptions
} from '@opentelemetry/exporter-metrics-otlp-http';
import { Resource } from '@opentelemetry/resources';
import {
SEMRESATTRS_SERVICE_NAME,
Expand Down Expand Up @@ -56,6 +59,10 @@ export interface OpenAPMOptions {
* @default "openmetrics"
*/
mode?: OpenAPMMode;
/**
*
*/
otlpMetricExporterOptions?: OTLPMetricExporterOptions;
/** Route where the metrics will be exposed
* @default "/metrics"
*/
Expand Down Expand Up @@ -97,6 +104,7 @@ const packageJson = getPackageJson();

export class OpenAPM extends LevitateEvents {
private mode: string;
private otlpMetricExporterOptions?: OTLPMetricExporterOptions;
private path: string;
private metricsServerPort: number;
readonly environment: string;
Expand All @@ -122,6 +130,9 @@ export class OpenAPM extends LevitateEvents {

this.mode = options?.mode ?? 'openmetrics';

if (this.mode === 'opentelemetry') {
this.otlpMetricExporterOptions = options?.otlpMetricExporterOptions;
}
// Initializing all the options
this.path = options?.path ?? '/metrics';
this.metricsServerPort = options?.metricsServerPort ?? 9097;
Expand Down Expand Up @@ -169,7 +180,7 @@ export class OpenAPM extends LevitateEvents {
);

const metricReader = new PeriodicExportingMetricReader({
exporter: new ConsoleMetricExporter(),
exporter: new OTLPMetricExporter(this.otlpMetricExporterOptions),
// Default is 60000ms (60 seconds). Set to 10 seconds for demonstrative purposes only.
exportIntervalMillis: 10000
prathamesh-sonpatki marked this conversation as resolved.
Show resolved Hide resolved
});
Expand Down
2 changes: 1 addition & 1 deletion src/clients/mysql2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ export const instrumentMySQL = (
createPool: typeof createPool;
createPoolCluster: typeof createPoolCluster;
},
mode: OpenAPMMode
mode: string
) => {
if (mode === 'opentelemetry') {
console.log('opentelemetry is not supported for mysql instrumentation');
Expand Down
Loading