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

[Shim] Add Support for Context.tags #1193

Merged
merged 85 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from 84 commits
Commits
Show all changes
85 commits
Select commit Hold shift + click to select a range
4786b2c
Add AutoCollectDependencies and Requests logic.
JacksonWeber Aug 2, 2023
e945d52
Merge branch 'beta' into jacksonweber/auto-collect
JacksonWeber Aug 2, 2023
159a40a
Add http.enable functionality and setUseDiskRetryCaching.
JacksonWeber Aug 2, 2023
2cb1bee
Add required no-op methods.
JacksonWeber Aug 2, 2023
4e47f07
Add methods to telemetryClient that were previously supported.
JacksonWeber Aug 2, 2023
822fdb7
Add global applicationinsights to
JacksonWeber Aug 3, 2023
055b1d5
Include possible way to handle config property on the TelemetryClient.
JacksonWeber Aug 3, 2023
e2d8af8
Set NodeHttp methods as no-ops.
JacksonWeber Aug 3, 2023
dae8c42
Framework for the config class to use with client.config.
JacksonWeber Aug 4, 2023
243c51c
Begin adding config properties to be modified on the client.
JacksonWeber Aug 4, 2023
20c4f77
Fix client.config initialization issue and implement config properties.
JacksonWeber Aug 5, 2023
0c77845
Add shim usage detection env var.
JacksonWeber Aug 5, 2023
053f3e7
Revert "Add shim usage detection env var."
JacksonWeber Aug 5, 2023
0ec4d4f
Apply env var updates.
JacksonWeber Aug 5, 2023
1536629
Fix env var check.
JacksonWeber Aug 5, 2023
a402c5b
Revert "Fix env var check."
JacksonWeber Aug 5, 2023
79bfa83
Env var.
JacksonWeber Aug 5, 2023
5832191
Update package-lock.
JacksonWeber Aug 5, 2023
c9d8fbc
Test if parseConfig is breaking functionaltests.
JacksonWeber Aug 5, 2023
cfe8a78
Update parseConfig to only run when in shim mode.
JacksonWeber Aug 5, 2023
481ea2e
Add more of the config parsing.
JacksonWeber Aug 6, 2023
c01fa91
Add final config values.
JacksonWeber Aug 6, 2023
45090e6
Begin tests for the client.confg.
JacksonWeber Aug 6, 2023
d028558
Fix distro tests and update httpInstrumentation configs.
JacksonWeber Aug 7, 2023
ac829e7
Update functionaltests.
JacksonWeber Aug 7, 2023
71ca8cc
Update package-lock.json
JacksonWeber Aug 7, 2023
dfedcd4
Test functional test update.
JacksonWeber Aug 7, 2023
1f4bda9
Is parseConfig breaking functionalTests?
JacksonWeber Aug 7, 2023
f20b688
Test parseConfig except enableAutoCollect methods.
JacksonWeber Aug 7, 2023
7ade280
Remove autoCollect logic.
JacksonWeber Aug 7, 2023
1a754c1
Test if we're wiping instrumentations configs when running autoCollec…
JacksonWeber Aug 7, 2023
36649b6
Update shim-applicationinsights.ts
JacksonWeber Aug 7, 2023
bc3a88c
Add flag to indicate shim is initialized so we know when to run
JacksonWeber Aug 8, 2023
d9198df
Implement noPatchModules and update noDiagnosticChannel.
JacksonWeber Aug 8, 2023
e0c754b
Add ContextTagKeys for implementing them on the context object.
JacksonWeber Aug 8, 2023
dfd3bf2
Fix import.
JacksonWeber Aug 8, 2023
c792250
Add support for further properties on the config and begin working on…
JacksonWeber Aug 9, 2023
f15676a
Write tests, and fix config parse methods.
JacksonWeber Aug 9, 2023
e995036
Add further tests, and update config methods that weren't working.
JacksonWeber Aug 9, 2023
488bce4
Add final config tests, and clean up duplicate code.
JacksonWeber Aug 9, 2023
7a7a3f4
Deliver warnings when trying to set unsupported values.
JacksonWeber Aug 9, 2023
2fcb4fd
Implement maxBatchInterval.
JacksonWeber Aug 9, 2023
3af3f1c
Remove tests and values not supported by client.config in AppInsights…
JacksonWeber Aug 11, 2023
e9db007
Test functionalTest.
JacksonWeber Aug 11, 2023
3e68e6d
Fix functional tests.
JacksonWeber Aug 11, 2023
2f7bc08
Test functionalTest.
JacksonWeber Aug 11, 2023
7a0025e
Update main.js
JacksonWeber Aug 11, 2023
4954405
Does parseConfig break functionalTests.
JacksonWeber Aug 11, 2023
4c56d69
Update client setup.
JacksonWeber Aug 11, 2023
11e586c
Remove unneded connStringParsing and enpointUrl contruction.
JacksonWeber Aug 11, 2023
18ad8ff
Convert config helper to a collection of functions.
JacksonWeber Aug 11, 2023
f78a9fe
Create NodeClient class.
JacksonWeber Aug 11, 2023
9272308
Add required JSON config values.
JacksonWeber Aug 11, 2023
a09ff93
Merge branch 'jacksonweber/auto-collect' into jacksonweber/json-config
JacksonWeber Aug 11, 2023
585cd7c
Setup for supporting the first JSON config value.
JacksonWeber Aug 12, 2023
c9c3834
Clean up telemetryClient.
JacksonWeber Aug 14, 2023
3cd463c
Make track messages more explicit.
JacksonWeber Aug 14, 2023
6c2e904
Merge branch 'jacksonweber/auto-collect' into jacksonweber/json-config
JacksonWeber Aug 14, 2023
ae14755
Add initial JSON config parsing update, deprecate instrumentationKey/…
JacksonWeber Aug 16, 2023
304939f
Merge branch 'beta' into jacksonweber/json-config
JacksonWeber Aug 16, 2023
650b9d3
Update telemetryClient.ts
JacksonWeber Aug 16, 2023
302dd86
Split JsonConfig into shim and non-shim files.
JacksonWeber Aug 17, 2023
b35f1c8
Clean up config files and begin adding tests.
JacksonWeber Aug 17, 2023
0ec5886
Resolve merge conflicts.
JacksonWeber Aug 17, 2023
89041b6
Fix duplicate files.
JacksonWeber Aug 17, 2023
3743c71
Clean up config files and add JSON tests.
JacksonWeber Aug 17, 2023
9d61570
Reconfigure file paths.
JacksonWeber Aug 17, 2023
a8c6e6f
Add JSON config file tests.
JacksonWeber Aug 18, 2023
d7936d2
Add tests for the configuration string and environment variables.
JacksonWeber Aug 18, 2023
29f8e29
Update applicationinsights.json
JacksonWeber Aug 18, 2023
bbeee38
Update JSON config fields.
JacksonWeber Aug 18, 2023
6df07c9
Merge branch 'beta' into jacksonweber/context-tags
JacksonWeber Aug 22, 2023
936a74e
Fix disabling http logic.
JacksonWeber Aug 22, 2023
c0daf56
Update and fix request tracking.
JacksonWeber Aug 22, 2023
11726ed
Add attribute processor and tests.
JacksonWeber Aug 22, 2023
3d6f6ee
Only run attribute processing in the shim.
JacksonWeber Aug 22, 2023
a0e5f67
Add logRecordProcessor for attaching context and update test.
JacksonWeber Aug 23, 2023
4def1ea
Update comment.
JacksonWeber Aug 23, 2023
4a30238
Resolve conflicts.
JacksonWeber Aug 29, 2023
ab02a77
Merge branch 'beta' into jacksonweber/context-tags
JacksonWeber Aug 29, 2023
5c08f16
Update package-lock.json
JacksonWeber Aug 29, 2023
35532af
Merge branch 'jacksonweber/context-tags' of https://github.com/Jackso…
JacksonWeber Aug 29, 2023
75f9304
Update package-lock.json
JacksonWeber Aug 29, 2023
83d0c0b
Remove unused import.
JacksonWeber Aug 29, 2023
af1ab1d
Use regular SpanProcessor.
JacksonWeber Aug 29, 2023
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
5,792 changes: 5,640 additions & 152 deletions package-lock.json

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions src/shared/util/attributeLogRecordProcessor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { BatchLogRecordProcessor, LogRecord, LogRecordExporter } from "@opentelemetry/sdk-logs";

export class AttributeLogProcessor extends BatchLogRecordProcessor {
private _attributes: { [key: string]: string };
constructor(exporter: LogRecordExporter, attributes: { [key: string]: string }) {
super(exporter);
this._attributes = attributes;
}
// Override onEmit to apply log record attributes before exporting
onEmit(record: LogRecord) {
JacksonWeber marked this conversation as resolved.
Show resolved Hide resolved
record.setAttributes(this._attributes);
super.onEmit(record);
}
}
16 changes: 16 additions & 0 deletions src/shared/util/attributeSpanProcessor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { BatchSpanProcessor, Span } from "@opentelemetry/sdk-trace-base";
import { SpanExporter } from "@opentelemetry/sdk-trace-node";
import { context } from "@opentelemetry/api";

export class AttributeSpanProcessor extends BatchSpanProcessor {
JacksonWeber marked this conversation as resolved.
Show resolved Hide resolved
private _attributes: { [key: string]: string };
constructor(exporter: SpanExporter, attributes: { [key: string]: string }) {
super(exporter);
this._attributes = attributes;
}
// Override onStart to apply span attributes before exporting
onStart(span: Span) {
span.setAttributes(this._attributes);
super.onStart(span, context.active());
}
}
4 changes: 2 additions & 2 deletions src/shared/util/configHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function setAutoCollectRequests(options: ApplicationInsightsOptions, valu
...options.instrumentationOptions?.http,
enabled: true,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
ignoreIncomingRequestHook: (request: http.RequestOptions) => true,
ignoreIncomingRequestHook: (request: http.IncomingMessage) => true,
} as HttpInstrumentationConfig
};
} else {
Expand All @@ -35,7 +35,7 @@ export function setAutoCollectRequests(options: ApplicationInsightsOptions, valu
...options.instrumentationOptions?.http,
enabled: true,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
ignoreIncomingRequestHook: (request: http.RequestOptions) => false,
ignoreIncomingRequestHook: (request: http.IncomingMessage) => false,
} as HttpInstrumentationConfig
};
}
Expand Down
2 changes: 1 addition & 1 deletion src/shim/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ class Config implements IConfig {

// NOT SUPPORTED CONFIGURATION OPTIONS
if (this.disableAppInsights) {
Logger.getInstance().warn("disableAppInsights cohnfiguration no longer supported.");
Logger.getInstance().warn("disableAppInsights configuration no longer supported.");
}
if (this.enableAutoCollectHeartbeat) {
Logger.getInstance().warn("Heartbeat metris are no longer supported.");
Expand Down
16 changes: 13 additions & 3 deletions src/shim/telemetryClient.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { Attributes, context, DiagLogLevel, SpanKind, SpanOptions, SpanStatusCode, trace } from "@opentelemetry/api";
import { Attributes, context, ProxyTracerProvider, SpanKind, SpanOptions, SpanStatusCode, trace } from "@opentelemetry/api";
import { logs } from "@opentelemetry/api-logs";
import { LoggerProvider } from "@opentelemetry/sdk-logs";
import { SemanticAttributes } from "@opentelemetry/semantic-conventions";

import * as Contracts from "../declarations/contracts";
import { TelemetryItem as Envelope } from "../declarations/generated";
import { Context } from "./context";
import { Logger } from "../shared/logging";
import { Util } from "../shared/util";
import Config = require("./config");
import { AzureMonitorTraceExporter, AzureMonitorLogExporter } from "@azure/monitor-opentelemetry-exporter";
import { AttributeSpanProcessor } from "../shared/util/attributeSpanProcessor";
import { NodeTracerProvider } from "@opentelemetry/sdk-trace-node";
import { AttributeLogProcessor } from "../shared/util/attributeLogRecordProcessor";
import { ApplicationInsightsClient } from "../applicationInsightsClient";
import { LogApi } from "../logs/api";


/**
* Application Insights telemetry client provides interface to track telemetry items, register telemetry initializers and
* and manually trigger immediate sending (flushing)
*/
export class TelemetryClient {
private _attributeSpanProcessor: AttributeSpanProcessor;
private _attributeLogProcessor: AttributeLogProcessor;
private _client: ApplicationInsightsClient;
private _logApi: LogApi;
public context: Context;
Expand All @@ -44,6 +49,11 @@ export class TelemetryClient {
// LoggerProvider would be initialized when client is instantiated
// Get Logger from global provider
this._logApi = new LogApi(logs.getLogger("ApplicationInsightsLogger"));
this._attributeSpanProcessor = new AttributeSpanProcessor(new AzureMonitorTraceExporter(this.config.parseConfig().azureMonitorExporterConfig), this.context.tags);
((trace.getTracerProvider() as ProxyTracerProvider).getDelegate() as NodeTracerProvider).addSpanProcessor(this._attributeSpanProcessor);

this._attributeLogProcessor = new AttributeLogProcessor(new AzureMonitorLogExporter(options.azureMonitorExporterConfig), this.context.tags);
(logs.getLoggerProvider() as LoggerProvider).addLogRecordProcessor(this._attributeLogProcessor);
}

/**
Expand Down
Loading
Loading