forked from Azure/azure-sdk-for-js
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Azure Monitor Exporter] Add support for Application Insights Standar…
…d Metrics (Azure#23591) * Add support for AI Standard Metrics * Addressing comments
- Loading branch information
1 parent
aba1e0a
commit c9d9360
Showing
8 changed files
with
301 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
sdk/monitor/monitor-opentelemetry-exporter/src/utils/common.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
import os from "os"; | ||
import { | ||
SemanticResourceAttributes, | ||
SemanticAttributes, | ||
DbSystemValues, | ||
} from "@opentelemetry/semantic-conventions"; | ||
import { Tags } from "../types"; | ||
import { getInstance } from "../platform"; | ||
import { KnownContextTagKeys } from "../generated"; | ||
import { Resource } from "@opentelemetry/resources"; | ||
import { Attributes } from "@opentelemetry/api"; | ||
|
||
export function createTagsFromResource(resource: Resource): Tags { | ||
const context = getInstance(); | ||
const tags: Tags = { ...context.tags }; | ||
if (resource && resource.attributes) { | ||
const serviceName = resource.attributes[SemanticResourceAttributes.SERVICE_NAME]; | ||
const serviceNamespace = resource.attributes[SemanticResourceAttributes.SERVICE_NAMESPACE]; | ||
if (serviceName) { | ||
if (serviceNamespace) { | ||
tags[KnownContextTagKeys.AiCloudRole] = `${serviceNamespace}.${serviceName}`; | ||
} else { | ||
tags[KnownContextTagKeys.AiCloudRole] = String(serviceName); | ||
} | ||
} | ||
const serviceInstanceId = resource.attributes[SemanticResourceAttributes.SERVICE_INSTANCE_ID]; | ||
if (serviceInstanceId) { | ||
tags[KnownContextTagKeys.AiCloudRoleInstance] = String(serviceInstanceId); | ||
} else { | ||
tags[KnownContextTagKeys.AiCloudRoleInstance] = os && os.hostname(); | ||
} | ||
const endUserId = resource.attributes[SemanticAttributes.ENDUSER_ID]; | ||
if (endUserId) { | ||
tags[KnownContextTagKeys.AiUserId] = String(endUserId); | ||
} | ||
} | ||
return tags; | ||
} | ||
|
||
export function isSqlDB(dbSystem: string) { | ||
return ( | ||
dbSystem === DbSystemValues.DB2 || | ||
dbSystem === DbSystemValues.DERBY || | ||
dbSystem === DbSystemValues.MARIADB || | ||
dbSystem === DbSystemValues.MSSQL || | ||
dbSystem === DbSystemValues.ORACLE || | ||
dbSystem === DbSystemValues.SQLITE || | ||
dbSystem === DbSystemValues.OTHER_SQL || | ||
dbSystem === DbSystemValues.HSQLDB || | ||
dbSystem === DbSystemValues.H2 | ||
); | ||
} | ||
|
||
export function getUrl(attributes: Attributes): string { | ||
if (!attributes) { | ||
return ""; | ||
} | ||
const httpMethod = attributes[SemanticAttributes.HTTP_METHOD]; | ||
if (httpMethod) { | ||
const httpUrl = attributes[SemanticAttributes.HTTP_URL]; | ||
if (httpUrl) { | ||
return String(httpUrl); | ||
} else { | ||
const httpScheme = attributes[SemanticAttributes.HTTP_SCHEME]; | ||
const httpTarget = attributes[SemanticAttributes.HTTP_TARGET]; | ||
if (httpScheme && httpTarget) { | ||
const httpHost = attributes[SemanticAttributes.HTTP_HOST]; | ||
if (httpHost) { | ||
return `${httpScheme}://${httpHost}${httpTarget}`; | ||
} else { | ||
const netPeerPort = attributes[SemanticAttributes.NET_PEER_PORT]; | ||
if (netPeerPort) { | ||
const netPeerName = attributes[SemanticAttributes.NET_PEER_NAME]; | ||
if (netPeerName) { | ||
return `${httpScheme}://${netPeerName}:${netPeerPort}${httpTarget}`; | ||
} else { | ||
const netPeerIp = attributes[SemanticAttributes.NET_PEER_IP]; | ||
if (netPeerIp) { | ||
return `${httpScheme}://${netPeerIp}:${netPeerPort}${httpTarget}`; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
return ""; | ||
} | ||
|
||
export function getDependencyTarget(attributes: Attributes): string { | ||
if (!attributes) { | ||
return ""; | ||
} | ||
const peerService = attributes[SemanticAttributes.PEER_SERVICE]; | ||
const httpHost = attributes[SemanticAttributes.HTTP_HOST]; | ||
const httpUrl = attributes[SemanticAttributes.HTTP_URL]; | ||
const netPeerName = attributes[SemanticAttributes.NET_PEER_NAME]; | ||
const netPeerIp = attributes[SemanticAttributes.NET_PEER_IP]; | ||
if (peerService) { | ||
return String(peerService); | ||
} else if (httpHost) { | ||
return String(httpHost); | ||
} else if (httpUrl) { | ||
return String(httpUrl); | ||
} else if (netPeerName) { | ||
return String(netPeerName); | ||
} else if (netPeerIp) { | ||
return String(netPeerIp); | ||
} | ||
return ""; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 0 additions & 39 deletions
39
sdk/monitor/monitor-opentelemetry-exporter/src/utils/resourceUtils.ts
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.