Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
import * as browserSdkLoaderHelper from "./browserSdkLoaderHelper.js";
import * as prefixHelper from "../utils/common.js";
import * as zlib from "zlib";
import type { InternalConfig } from "../shared/index.js";
import type { InternalConfig } from "../../shared/index.js";
import { ConnectionStringParser } from "../utils/connectionStringParser.js";
import type { IncomingMessage, ServerResponse } from "node:http";
import { Logger } from "../shared/logging/logger.js";
import { BROWSER_SDK_LOADER_DEFAULT_SOURCE } from "../types.js";
import { Logger } from "../../shared/logging/logger.js";
import { BROWSER_SDK_LOADER_DEFAULT_SOURCE } from "../../types.js";
import { diag } from "@opentelemetry/api";

export class BrowserSdkLoader {
Expand Down Expand Up @@ -93,7 +93,7 @@
const originalHttpServer = http.createServer;
const originalHttpsServer = https.createServer;

(http.createServer as any) = (

Check warning on line 96 in src/azureMonitor/browserSdkLoader/browserSdkLoader.ts

View workflow job for this annotation

GitHub Actions / ESLint

Unexpected any. Specify a different type
requestListener?: (request: IncomingMessage, response: ServerResponse) => void,
) => {
const originalRequestListener = requestListener;
Expand Down Expand Up @@ -137,7 +137,7 @@
Logger.getInstance().warn(`Inject browser sdk loader error: ${err}`);
}
// eslint-disable-next-line prefer-rest-params
return originalResponseWrite.apply(response, arguments as any);

Check warning on line 140 in src/azureMonitor/browserSdkLoader/browserSdkLoader.ts

View workflow job for this annotation

GitHub Actions / ESLint

Unexpected any. Specify a different type
};

// Patch response end method for cases when HTML is added there
Expand All @@ -145,7 +145,7 @@
const originalResponseEnd = response.end;

// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
(response.end as any) = function wrap(a?: Buffer | string | any, b?: Function) {

Check warning on line 148 in src/azureMonitor/browserSdkLoader/browserSdkLoader.ts

View workflow job for this annotation

GitHub Actions / ESLint

Unexpected any. Specify a different type

Check warning on line 148 in src/azureMonitor/browserSdkLoader/browserSdkLoader.ts

View workflow job for this annotation

GitHub Actions / ESLint

Unexpected any. Specify a different type
if (isGetRequest) {
try {
if (isGetRequest) {
Expand Down Expand Up @@ -179,7 +179,7 @@
}
}
// eslint-disable-next-line prefer-rest-params
return originalResponseEnd.apply(response, arguments as any);

Check warning on line 182 in src/azureMonitor/browserSdkLoader/browserSdkLoader.ts

View workflow job for this annotation

GitHub Actions / ESLint

Unexpected any. Specify a different type
};

return originalRequestListener(request, response);
Expand All @@ -188,7 +188,7 @@
return originalHttpServer(requestListener);
};

(https.createServer as any) = function (options: any, httpsRequestListener: any): any {

Check warning on line 191 in src/azureMonitor/browserSdkLoader/browserSdkLoader.ts

View workflow job for this annotation

GitHub Actions / ESLint

Unexpected any. Specify a different type

Check warning on line 191 in src/azureMonitor/browserSdkLoader/browserSdkLoader.ts

View workflow job for this annotation

GitHub Actions / ESLint

Unexpected any. Specify a different type

Check warning on line 191 in src/azureMonitor/browserSdkLoader/browserSdkLoader.ts

View workflow job for this annotation

GitHub Actions / ESLint

Unexpected any. Specify a different type
const originalHttpsRequestListener = httpsRequestListener;
if (originalHttpsRequestListener) {
httpsRequestListener = function (req: any, res: any) {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,23 @@ export function _publishSend(
allowReserved: options?.requestOptions?.skipUrlEncoding,
},
);
return context
.path(path)
.post({
...operationOptionsToRequestParameters(options),
contentType: "application/json",
headers: {
...(options?.configurationEtag !== undefined
? { "x-ms-qps-configuration-etag": options?.configurationEtag }
: {}),
...(options?.transmissionTime !== undefined
? { "x-ms-qps-transmission-time": options?.transmissionTime }
: {}),
accept: "application/json",
...options.requestOptions?.headers,
},
body: !options["monitoringDataPoints"]
? options["monitoringDataPoints"]
: monitoringDataPointArraySerializer(options["monitoringDataPoints"]),
});
return context.path(path).post({
...operationOptionsToRequestParameters(options),
contentType: "application/json",
headers: {
...(options?.configurationEtag !== undefined
? { "x-ms-qps-configuration-etag": options?.configurationEtag }
: {}),
...(options?.transmissionTime !== undefined
? { "x-ms-qps-transmission-time": options?.transmissionTime }
: {}),
accept: "application/json",
...options.requestOptions?.headers,
},
body: !options["monitoringDataPoints"]
? options["monitoringDataPoints"]
: monitoringDataPointArraySerializer(options["monitoringDataPoints"]),
});
}

export async function _publishDeserialize(
Expand Down Expand Up @@ -92,36 +90,34 @@ export function _isSubscribedSend(
allowReserved: options?.requestOptions?.skipUrlEncoding,
},
);
return context
.path(path)
.post({
...operationOptionsToRequestParameters(options),
contentType: "application/json",
headers: {
...(options?.transmissionTime !== undefined
? { "x-ms-qps-transmission-time": options?.transmissionTime }
: {}),
...(options?.machineName !== undefined
? { "x-ms-qps-machine-name": options?.machineName }
: {}),
...(options?.instanceName !== undefined
? { "x-ms-qps-instance-name": options?.instanceName }
: {}),
...(options?.streamId !== undefined ? { "x-ms-qps-stream-id": options?.streamId } : {}),
...(options?.roleName !== undefined ? { "x-ms-qps-role-name": options?.roleName } : {}),
...(options?.invariantVersion !== undefined
? { "x-ms-qps-invariant-version": options?.invariantVersion }
: {}),
...(options?.configurationEtag !== undefined
? { "x-ms-qps-configuration-etag": options?.configurationEtag }
: {}),
accept: "application/json",
...options.requestOptions?.headers,
},
body: !options["monitoringDataPoint"]
? options["monitoringDataPoint"]
: monitoringDataPointSerializer(options["monitoringDataPoint"]),
});
return context.path(path).post({
...operationOptionsToRequestParameters(options),
contentType: "application/json",
headers: {
...(options?.transmissionTime !== undefined
? { "x-ms-qps-transmission-time": options?.transmissionTime }
: {}),
...(options?.machineName !== undefined
? { "x-ms-qps-machine-name": options?.machineName }
: {}),
...(options?.instanceName !== undefined
? { "x-ms-qps-instance-name": options?.instanceName }
: {}),
...(options?.streamId !== undefined ? { "x-ms-qps-stream-id": options?.streamId } : {}),
...(options?.roleName !== undefined ? { "x-ms-qps-role-name": options?.roleName } : {}),
...(options?.invariantVersion !== undefined
? { "x-ms-qps-invariant-version": options?.invariantVersion }
: {}),
...(options?.configurationEtag !== undefined
? { "x-ms-qps-configuration-etag": options?.configurationEtag }
: {}),
accept: "application/json",
...options.requestOptions?.headers,
},
body: !options["monitoringDataPoint"]
? options["monitoringDataPoint"]
: monitoringDataPointSerializer(options["monitoringDataPoint"]),
});
}

export async function _isSubscribedDeserialize(
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
* This file contains only generated model types and their (de)serializers.
* Disable the following rules for internal models with '_' prefix and deserializers which require 'any' for raw JSON input.
*/



/** Monitoring data point coming from the client, which includes metrics, documents and other metadata info. */
export interface MonitoringDataPoint {
/** Application Insights SDK version. */
Expand Down
6 changes: 3 additions & 3 deletions src/azureMonitorSetup.ts → src/azureMonitor/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
* Azure Monitor concerns — not part of the generic OTel distro lifecycle.
*/

import type { InternalConfig } from "./shared/config.js";
import type { StatsbeatFeatures, StatsbeatInstrumentations } from "./types.js";
import { APPLICATIONINSIGHTS_SDKSTATS_DISABLED } from "./types.js";
import type { InternalConfig } from "../shared/config.js";
import type { StatsbeatFeatures, StatsbeatInstrumentations } from "../types.js";
import { APPLICATIONINSIGHTS_SDKSTATS_DISABLED } from "../types.js";
import { BrowserSdkLoader } from "./browserSdkLoader/browserSdkLoader.js";
import { setSdkPrefix } from "./metrics/quickpulse/utils.js";
import { getInstance } from "./utils/statsbeat.js";
Expand Down
4 changes: 2 additions & 2 deletions src/loader.ts → src/azureMonitor/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
*/

import * as nodeModule from "node:module";
import { Logger } from "./shared/logging/index.js";
import { getModuleParentURL } from "./shared/module.js";
import { Logger } from "../shared/logging/index.js";
import { getModuleParentURL } from "../shared/module.js";

const OTEL_LOADER_SPECIFIER = "@opentelemetry/instrumentation/hook.mjs";

Expand Down
2 changes: 1 addition & 1 deletion src/logs/handler.ts → src/azureMonitor/logs/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { Instrumentation } from "@opentelemetry/instrumentation";
import { BunyanInstrumentation } from "@opentelemetry/instrumentation-bunyan";
import { WinstonInstrumentation } from "@opentelemetry/instrumentation-winston";
import type { BatchLogRecordProcessor } from "@opentelemetry/sdk-logs";
import type { InternalConfig } from "../shared/config.js";
import type { InternalConfig } from "../../shared/config.js";
import type { MetricHandler } from "../metrics/handler.js";
import { AzureLogRecordProcessor } from "./logRecordProcessor.js";
import { AzureBatchLogRecordProcessor } from "./batchLogRecordProcessor.js";
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import type { MetricHandler } from "../metrics/handler.js";
import type { LogRecordProcessor, SdkLogRecord } from "@opentelemetry/sdk-logs";
import { Logger } from "../shared/logging/index.js";
import { Logger } from "../../shared/logging/index.js";

/**
* Azure Monitor LogRecord Processor.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ import {
PeriodicExportingMetricReader,
} from "@opentelemetry/sdk-metrics";
import type { SdkLogRecord } from "@opentelemetry/sdk-logs";
import type { InternalConfig } from "../shared/config.js";
import type { InternalConfig } from "../../shared/config.js";
import { StandardMetrics } from "./standardMetrics.js";
import type { ReadableSpan, Span } from "@opentelemetry/sdk-trace-base";
import { APPLICATION_INSIGHTS_NO_STANDARD_METRICS, HISTOGRAM_AGGREGATION_MAP } from "./types.js";
import { LiveMetrics } from "./quickpulse/liveMetrics.js";
import { PerformanceCounterMetrics } from "./performanceCounters.js";
import { Logger } from "../shared/logging/index.js";
import { Logger } from "../../shared/logging/index.js";

type MetricExporterOptions = ConstructorParameters<typeof AzureMonitorMetricExporter>[0];

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ import { MeterProvider, PeriodicExportingMetricReader } from "@opentelemetry/sdk
import type { ReadableSpan, TimedEvent } from "@opentelemetry/sdk-trace-base";
import { PerformanceCounterMetricNames } from "./types.js";
import { hrTimeToMilliseconds } from "@opentelemetry/core";
import type { InternalConfig } from "../shared/config.js";
import type { InternalConfig } from "../../shared/config.js";
import { getLogData, isExceptionData } from "./quickpulse/utils.js";
import type { ExceptionData, TraceData } from "./quickpulse/types.js";
import { Logger } from "../shared/logging/logger.js";
import { Logger } from "../../shared/logging/logger.js";
import { readAvailableMemory } from "./utils.js";
import process from "node:process";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type {
} from "@opentelemetry/sdk-metrics";
import { MeterProvider, PeriodicExportingMetricReader } from "@opentelemetry/sdk-metrics";
import type { SdkLogRecord } from "@opentelemetry/sdk-logs";
import type { InternalConfig } from "../../shared/config.js";
import type { InternalConfig } from "../../../shared/config.js";
import type { Meter, ObservableGauge, ObservableResult } from "@opentelemetry/api";
import { SpanKind, SpanStatusCode, ValueType, context } from "@opentelemetry/api";
import type { ReadableSpan, TimedEvent } from "@opentelemetry/sdk-trace-base";
Expand Down Expand Up @@ -40,7 +40,7 @@ import {
import { QuickpulseMetricExporter } from "./export/exporter.js";
import { QuickpulseSender } from "./export/sender.js";
import { ConnectionStringParser } from "../../utils/connectionStringParser.js";
import { DEFAULT_LIVEMETRICS_ENDPOINT } from "../../types.js";
import { DEFAULT_LIVEMETRICS_ENDPOINT } from "../../../types.js";
import type {
QuickpulseExporterOptions,
RequestData,
Expand All @@ -66,7 +66,7 @@ import {
import { SEMATTRS_EXCEPTION_TYPE } from "@opentelemetry/semantic-conventions";
import { getPhysicalMemory, getProcessorTimeNormalized } from "../utils.js";
import { getCloudRole, getCloudRoleInstance } from "../utils.js";
import { Logger } from "../../shared/logging/logger.js";
import { Logger } from "../../../shared/logging/logger.js";

const POST_INTERVAL = 1000;
const MAX_POST_WAIT_TIME = 20000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ import {
AZURE_MONITOR_OPENTELEMETRY_VERSION,
AZURE_MONITOR_PREFIX,
AttachTypePrefix,
} from "../../types.js";
} from "../../../types.js";
import type {
RequestData,
DependencyData,
Expand All @@ -82,7 +82,7 @@ import { getOsPrefix } from "../../utils/common.js";
import { getResourceProvider } from "../../utils/common.js";
import type { LogAttributes } from "@opentelemetry/api-logs";
import { getDependencyTarget, isSqlDB, isExceptionTelemetry } from "../utils.js";
import { Logger } from "../../shared/logging/index.js";
import { Logger } from "../../../shared/logging/index.js";

/** Get the internal SDK version */
export function getSdkVersion(): string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type {
} from "@opentelemetry/sdk-metrics";
import { MeterProvider, PeriodicExportingMetricReader } from "@opentelemetry/sdk-metrics";
import type { SdkLogRecord } from "@opentelemetry/sdk-logs";
import type { InternalConfig } from "../shared/config.js";
import type { InternalConfig } from "../../shared/config.js";
import { AzureMonitorMetricExporter } from "@azure/monitor-opentelemetry-exporter";
import type { Counter, Histogram, Meter } from "@opentelemetry/api";
import { SpanKind, ValueType } from "@opentelemetry/api";
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import {
getNetPeerName,
getUserAgent,
} from "./quickpulse/utils.js";
import { Logger } from "../shared/logging/logger.js";
import { Logger } from "../../shared/logging/logger.js";
import os from "node:os";
import process from "node:process";
import { readFileSync } from "node:fs";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { MySQLInstrumentation } from "@opentelemetry/instrumentation-mysql";
import { PgInstrumentation } from "@opentelemetry/instrumentation-pg";
import { RedisInstrumentation } from "@opentelemetry/instrumentation-redis";

import type { InternalConfig } from "../shared/config.js";
import type { InternalConfig } from "../../shared/config.js";
import type { MetricHandler } from "../metrics/handler.js";
import { ignoreOutgoingRequestHook } from "../utils/common.js";
import { AzureMonitorSpanProcessor } from "./spanProcessor.js";
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type { Link, Attributes, SpanKind, Context } from "@opentelemetry/api";
import { diag } from "@opentelemetry/api";
import type { Sampler, SamplingResult } from "@opentelemetry/sdk-trace-base";
import { SamplingDecision } from "@opentelemetry/sdk-trace-base";
import { AzureMonitorSampleRate } from "../types.js";
import { AzureMonitorSampleRate } from "../../types.js";

/**
* ApplicationInsightsSampler is responsible for the following:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import type { Context } from "@opentelemetry/api";
import type { ReadableSpan, Span, SpanProcessor } from "@opentelemetry/sdk-trace-base";
import type { MetricHandler } from "../metrics/index.js";
import { Logger } from "../shared/logging/index.js";
import { Logger } from "../../shared/logging/index.js";

/**
* Azure Monitor Span Processor.
Expand Down
105 changes: 105 additions & 0 deletions src/azureMonitor/utils/common.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import type http from "node:http";

export function ignoreOutgoingRequestHook(request: http.RequestOptions): boolean {
if (request && request.headers && !Array.isArray(request.headers)) {
const outgoingHeaders = request.headers as http.OutgoingHttpHeaders;
if (
(outgoingHeaders["User-Agent"] &&
outgoingHeaders["User-Agent"]
.toString()
.indexOf("azsdk-js-monitor-opentelemetry-exporter") > -1) ||
(outgoingHeaders["user-agent"] &&
outgoingHeaders["user-agent"]
.toString()
.indexOf("azsdk-js-monitor-opentelemetry-exporter") > -1)
) {
return true;
}
}
return false;
}

export const isWindows = (): boolean => {
return process.platform === "win32";
};

export const isLinux = (): boolean => {
return process.platform === "linux";
};

export const isDarwin = (): boolean => {
return process.platform === "darwin";
};

/**
* Get prefix for OS
* Windows system: "w"
* Linux system: "l"
* non-Windows and non-Linux system: "u" (unknown)
*/
export const getOsPrefix = (): string => {
return isWindows() ? "w" : isLinux() ? "l" : "u";
};

/**
* Get prefix resource provider, vm will considered as "unknown RP"
* Web App: "a"
* Function App: "f"
* non-Web and non-Function APP: "u" (unknown)
*/
export const isAppService = (): boolean => {
return process.env.WEBSITE_SITE_NAME && !process.env.FUNCTIONS_WORKER_RUNTIME ? true : false;
};

export const isFunctionApp = (): boolean => {
return process.env.FUNCTIONS_WORKER_RUNTIME ? true : false;
};

export const isAks = (): boolean => {
return process.env.AKS_ARM_NAMESPACE_ID || process.env.KUBERNETES_SERVICE_HOST ? true : false;
};

/**
* Get prefix resource provider, vm will considered as "unknown RP"
* Web App: "a"
* Function App: "f"
* AKS: "k"
* non-Web and non-Function APP: "u" (unknown)
*/
export const getResourceProvider = (): string => {
if (isAppService()) {
return "a";
}
if (isFunctionApp()) {
return "f";
}
if (isAks()) {
return "k";
}
return "u";
};

/**
* Convert milliseconds to Breeze expected time.
* @internal
*/
export function msToTimeSpan(ms: number): string {
let totalms = ms;
if (Number.isNaN(totalms) || totalms < 0 || !Number.isFinite(ms)) {
totalms = 0;
}

let sec = ((totalms / 1000) % 60).toFixed(7).replace(/0{0,4}$/, "");
let min = `${Math.floor(totalms / (1000 * 60)) % 60}`;
let hour = `${Math.floor(totalms / (1000 * 60 * 60)) % 24}`;
const days = Math.floor(totalms / (1000 * 60 * 60 * 24));

sec = sec.indexOf(".") < 2 ? `0${sec}` : sec;
min = min.length < 2 ? `0${min}` : min;
hour = hour.length < 2 ? `0${hour}` : hour;
const daysText = days > 0 ? `${days}.` : "";

return `${daysText + hour}:${min}:${sec}`;
}
Loading
Loading