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

[Azure Monitor OpenTelemetry Exporter] Capture Measurements when Creating Logs #29511

Merged
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
6 changes: 6 additions & 0 deletions sdk/monitor/monitor-opentelemetry-exporter/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Release History

## Unreleased ()

### Features Added

- Capture and export measurements when creating log records from the Application Insights 3.X SDK.

## 1.0.0-beta.22 (2024-04-16)

### Features Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export function logToEnvelope(log: ReadableLogRecord, ikey: string): Envelope |
const sampleRate = 100;
const instrumentationKey = ikey;
const tags = createTagsFromLog(log);
const [properties, measurements] = createPropertiesFromLog(log);
let [properties, measurements] = createPropertiesFromLog(log);
let name: string;
let baseType: string;
let baseData: MonitorDomain;
Expand Down Expand Up @@ -85,6 +85,7 @@ export function logToEnvelope(log: ReadableLogRecord, ikey: string): Envelope |
baseType = String(log.attributes[ApplicationInsightsBaseType]);
name = getLegacyApplicationInsightsName(log);
baseData = getLegacyApplicationInsightsBaseData(log);
measurements = getLegacyApplicationInsightsMeasurements(log);
if (!baseData) {
// Failed to parse log
return;
Expand Down Expand Up @@ -180,6 +181,14 @@ function getLegacyApplicationInsightsName(log: ReadableLogRecord): string {
return name;
}

function getLegacyApplicationInsightsMeasurements(log: ReadableLogRecord): Measurements {
let measurements: Measurements = {};
if ((log.body as MonitorDomain)?.measurements) {
measurements = { ...(log.body as MonitorDomain).measurements };
}
return measurements;
}

function getLegacyApplicationInsightsBaseData(log: ReadableLogRecord): MonitorDomain {
let baseData: MonitorDomain = {
version: 2,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ describe("logUtils.ts", () => {
severityLevel: `Information`,
version: 2,
properties: expectedProperties,
measurements: {},
measurements: emptyMeasurements,
};

const envelope = logToEnvelope(testLogRecord as ReadableLogRecord, "ikey");
Expand Down Expand Up @@ -178,6 +178,7 @@ describe("logUtils.ts", () => {
const data: MessageData = {
message: "testMessage",
severityLevel: "Verbose",
measurements: { testMeasurement: 1 },
version: 2,
};
testLogRecord.attributes = {
Expand All @@ -192,12 +193,15 @@ describe("logUtils.ts", () => {
"extra.attribute": "foo",
[SemanticAttributes.MESSAGE_TYPE]: "test message type",
};
const expectedMeasurements: Measurements = {
testMeasurement: 1,
};
const expectedBaseData: Partial<MessageData> = {
message: `testMessage`,
severityLevel: `Verbose`,
version: 2,
properties: expectedProperties,
measurements: {},
measurements: expectedMeasurements,
};

const envelope = logToEnvelope(testLogRecord as ReadableLogRecord, "ikey");
Expand All @@ -207,7 +211,7 @@ describe("logUtils.ts", () => {
100,
"MessageData",
expectedProperties,
emptyMeasurements,
expectedMeasurements,
expectedBaseData,
expectedTime,
);
Expand Down
Loading