Skip to content
Closed
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
9 changes: 9 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
"@opentelemetry/exporter-metrics-otlp-http": "^0.43.0",
"@opentelemetry/exporter-trace-otlp-http": "^0.43.0",
"@opentelemetry/otlp-exporter-base": "^0.43.0",
"@opentelemetry/resource-detector-azure": "^0.2.0",
"@opentelemetry/resources": "^1.16.0",
"@opentelemetry/sdk-logs": "^0.43.0",
"@opentelemetry/sdk-metrics": "^1.16.0",
Expand Down
16 changes: 3 additions & 13 deletions src/agent/appServicesLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@

import * as os from 'os';
import * as path from 'path';
import { Attributes } from '@opentelemetry/api';
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
import { Resource } from '@opentelemetry/resources';
import { DiagnosticLogger } from './diagnostics/diagnosticLogger';
import { FileWriter } from "./diagnostics/writers/fileWriter";
import { StatusLogger } from "./diagnostics/statusLogger";
import { AgentLoader } from "./agentLoader";
import { AgentResourceProviderType, AZURE_MONITOR_AGENT_PREFIX } from './types';
import { detectResourcesSync } from '@opentelemetry/resources';
import { azureAppServiceDetector } from '@opentelemetry/resource-detector-azure';


export class AppServicesLoader extends AgentLoader {
Expand All @@ -19,16 +18,7 @@ export class AppServicesLoader extends AgentLoader {
super();
if (this._canLoad) {
// Azure App Services specific configuration
const resourceAttributes: Attributes = {};
if (process.env.WEBSITE_SITE_NAME) {
resourceAttributes[SemanticResourceAttributes.SERVICE_NAME] =
process.env.WEBSITE_SITE_NAME;
}
if (process.env.WEBSITE_INSTANCE_ID) {
resourceAttributes[SemanticResourceAttributes.SERVICE_INSTANCE_ID] =
process.env.WEBSITE_INSTANCE_ID;
}
const resource = new Resource(resourceAttributes);
const resource = detectResourcesSync({ detectors: [azureAppServiceDetector] });
this._options.resource = resource;

let statusLogDir = '/var/log/applicationinsights/';
Expand Down
19 changes: 5 additions & 14 deletions src/agent/azureFunctionsLoader.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { Resource } from "@opentelemetry/resources";
import { AgentLoader } from "./agentLoader";
import { DiagnosticLogger } from "./diagnostics/diagnosticLogger";
import { StatusLogger } from "./diagnostics/statusLogger";
import { AzureFunctionsWriter } from "./diagnostics/writers/azureFunctionsWriter";
import { AgentResourceProviderType, AZURE_MONITOR_AGENT_PREFIX } from "./types";
import { Attributes } from "@opentelemetry/api";
import { SemanticResourceAttributes } from "@opentelemetry/semantic-conventions";
import { detectResourcesSync } from '@opentelemetry/resources';
import { azureFunctionsDetector } from '@opentelemetry/resource-detector-azure/build/src/detectors/AzureFunctionsDetector';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excuse the strange import path here. Functions detector isn't exported from the index in the resource detector. Addressed here: open-telemetry/opentelemetry-js-contrib#1800


export class AzureFunctionsLoader extends AgentLoader {

Expand All @@ -17,17 +16,9 @@ export class AzureFunctionsLoader extends AgentLoader {
if (this._canLoad) {
// Azure Fn specific configuration
this._options.enableAutoCollectPerformance = false;
process.env["APPLICATION_INSIGHTS_NO_STANDARD_METRICS"] = "disable";
const resourceAttributes: Attributes = {};
if (process.env.WEBSITE_SITE_NAME) {
resourceAttributes[SemanticResourceAttributes.SERVICE_NAME] =
process.env.WEBSITE_SITE_NAME;
}
if (process.env.WEBSITE_INSTANCE_ID) {
resourceAttributes[SemanticResourceAttributes.SERVICE_INSTANCE_ID] =
process.env.WEBSITE_INSTANCE_ID;
}
const resource = new Resource(resourceAttributes);
const resource = detectResourcesSync({
detectors: [azureFunctionsDetector],
});
this._options.resource = resource;

const writer = new AzureFunctionsWriter(this._instrumentationKey);
Expand Down
4 changes: 2 additions & 2 deletions test/unitTests/agent/azureFunctionsLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ describe("agent/AzureFunctionsLoader", () => {
// Agent Loader called
assert.ok(stub.calledOnce);
assert.equal(
agent["_options"].resource.attributes[SemanticResourceAttributes.SERVICE_INSTANCE_ID],
agent["_options"].resource.attributes[SemanticResourceAttributes.FAAS_INSTANCE],
"testRoleInstanceId"
);
assert.equal(
agent["_options"].resource.attributes[SemanticResourceAttributes.SERVICE_NAME],
agent["_options"].resource.attributes[SemanticResourceAttributes.FAAS_NAME],
"testRole"
);
});
Expand Down