@opentelemetry/resource-detector-azure
OpenTelemetry SDK resource detector for Azure
Last updated 22 days ago by GitHub Actions .
Apache-2.0 · Repository · Bugs · Original npm · Tarball · package.json
$ npm install @opentelemetry/resource-detector-azure 
SYNC missed versions from official npm registry.

OpenTelemetry Resource Detector for Azure

NPM Published Version Apache License

component owners: @JacksonWeber

Resource detector for Azure.

Installation

npm install --save @opentelemetry/resource-detector-azure

Usage

import { detectResources } from '@opentelemetry/resources';
import { azureAppServiceDetector } from '@opentelemetry/resource-detector-azure';
const resource = detectResources({
    detectors: [azureAppServiceDetector],
});

const tracerProvider = new NodeTracerProvider({ resource });

Available Detectors

This package implements Semantic Convention Version 1.37.0.

App Service Resource Detector

Resource Attribute Description
azure.app.service.stamp The specific "stamp" cluster within Azure where the App Service is running, e.g., "waws-prod-sn1-001". Value of Process Environment Variable APP_SERVICE_ATTRIBUTE_ENV_VARS.
cloud.platform The cloud platform. Here, it's always "azure.app_service".
cloud.provider The cloud service provider. In this context, it's always "azure".
cloud.region The Azure region where the App Service is hosted, e.g., "East US", "West Europe", etc. Value of Process Environment Variable REGION_NAME.
cloud.resource_id The Azure Resource Manager URI uniquely identifying the Azure App Service. Typically in the format /subscriptions/{subscriptionId}/resourceGroups/{groupName}/providers/Microsoft.Web/sites/{siteName}.
deployment.environment.name The deployment slot where the Azure App Service is running, such as "staging", "production", etc. Value of Process Environment Variable WEBSITE_SLOT_NAME.
host.id The primary hostname for the app, excluding any custom hostnames. Value of Process Environment Variable WEBSITE_HOSTNAME.
service.instance.id The specific instance of the Azure App Service, useful in a scaled-out configuration. Value of Process Environment Variable WEBSITE_INSTANCE_ID.
service.name The name of the Azure App Service. Value of Process Environment Variable WEBSITE_SITE_NAME.

VM Resource Detector

Resource Attribute Description
azure.vm.scaleset.name The name of the Virtual Machine Scale Set if the VM is part of one. Value from vmScaleSetName key on /metadata/instance/compute request.
azure.vm.sku The SKU of the Azure Virtual Machine's operating system. For instance, for a VM running Windows Server 2019 Datacenter edition, this value would be "2019-Datacenter". Value from sku key on /metadata/instance/compute request.
cloud.platform The cloud platform, which is always set to "azure.vm" in this context.
cloud.provider The cloud service provider, which is always set to "azure" in this context.
cloud.region The Azure region where the Virtual Machine is hosted, such as "East US", "West Europe", etc. Value from location key on /metadata/instance/compute request.
cloud.resource_id The Azure Resource Manager URI uniquely identifying the Azure Virtual Machine. It typically follows this format: /subscriptions/{subscriptionId}/resourceGroups/{groupName}/providers/Microsoft.Compute/virtualMachines/{vmName}. Value from resourceId key on /metadata/instance/compute request.
host.id A unique identifier for the VM host, for instance, "02aab8a4-74ef-476e-8182-f6d2ba4166a6". Value from vmId key on /metadata/instance/compute request.
host.name The name of the host machine. Value from name key on /metadata/instance/compute request.
host.type The size of the VM instance, for example, "Standard_D2s_v3". Value from vmSize key on /metadata/instance/compute request.
os.version The version of the operating system running on the VM. Value from version key on /metadata/instance/compute request.

Azure Functions Resource Detector

Resource Attribute Description
cloud.platform The cloud platform. Here, it's always "azure.functions".
cloud.provider The cloud service provider. In this context, it's always "azure".
cloud.region The Azure region where the Azure Function is hosted, e.g., "East US", "West Europe", etc. Value of Process Environment Variable REGION_NAME.
faas.instance The specific instance of the Azure App Service, useful in a scaled-out configuration. Value from Process Environment Variable WEBSITE_INSTANCE_ID.
faas.max_memory The amount of memory available to the Azure Function expressed in MiB. value from Process Environment Variable WEBSITE_MEMORY_LIMIT_MB.
service.name The name of the service the Azure Functions runs within. Value from Process Environment Variable WEBSITE_SITE_NAME.
cloud.resource_id The Azure Resource Manager URI uniquely identifying the Azure Virtual Machine. It typically follows this format: /subscriptions/{subscriptionId}/resourceGroups/{groupName}/providers/Microsoft.Compute/virtualMachines/{vmName}. Value from resourceId key on /metadata/instance/compute request.
process.pid The process ID collected from the running process.

Azure Container Apps Resource Detector

Resource Attribute Description
azure.container_app.version The revision of the Azure Container App. Value of Process Environment Variable CONTAINER_APP_REVISION.
cloud.platform The cloud platform. Here, it's always "azure.container_apps".
cloud.provider The cloud service provider. In this context, it's always "azure".
azure.container_app.name The name of the Azure Container App. Value of Process Environment Variable CONTAINER_APP_NAME.
host.name The hostname of the container. Value of Process Environment Variable `CONTAINER_APP_HOSTNAME.
azure.container_app.instance.id The replica name of the Azure Container App instance. Value of Process Environment Variable CONTAINER_APP_REPLICA_NAME.

Azure Kubernetes Service (AKS) Resource Detector

The AKS detector reads cluster metadata from the native aks-cluster-metadata ConfigMap in the kube-public namespace, which is automatically created by AKS. The ConfigMap contains a clusterResourceId key with the full ARM resource ID of the cluster.

Resource Attribute Description
cloud.platform The cloud platform. Here, it's always "azure.aks".
cloud.provider The cloud service provider. In this context, it's always "azure".
cloud.resource_id The Azure Resource Manager URI uniquely identifying the AKS cluster. Value from clusterResourceId key in the aks-cluster-metadata ConfigMap.
k8s.cluster.name The name of the AKS cluster, extracted from the ARM resource ID.
k8s.pod.name The pod name, read from K8S_POD_NAME when supplied through the Kubernetes Downward API.
k8s.pod.uid The pod UID, read from K8S_POD_UID when supplied through the Kubernetes Downward API.

Usage

To use the AKS detector, configure your pod to read from the native aks-cluster-metadata ConfigMap in the kube-public namespace:

env:
  - name: CLUSTER_RESOURCE_ID
    valueFrom:
      configMapKeyRef:
        name: aks-cluster-metadata
        key: clusterResourceId

Alternatively, you can mount the ConfigMap at /etc/kubernetes/aks-cluster-metadata. Kubernetes projects each key into its own file, so the detector reads the resource ID from /etc/kubernetes/aks-cluster-metadata/clusterResourceId:

volumes:
  - name: aks-cluster-metadata
    configMap:
      name: aks-cluster-metadata
volumeMounts:
  - name: aks-cluster-metadata
    mountPath: /etc/kubernetes/aks-cluster-metadata

Mounting the single key with subPath, so that /etc/kubernetes/aks-cluster-metadata is itself a file holding the resource ID, is also supported.

Note that the aks-cluster-metadata ConfigMap lives in the kube-public namespace, and Kubernetes resolves configMapKeyRef and ConfigMap volumes within the pod's own namespace. To consume it from another namespace, copy the ConfigMap into that namespace, or have tooling such as an init container read it and write the value to one of the supported locations above.

To also populate pod identity, add these environment variables to your application container alongside either cluster metadata configuration above:

env:
  - name: K8S_POD_NAME
    valueFrom:
      fieldRef:
        fieldPath: metadata.name
  - name: K8S_POD_UID
    valueFrom:
      fieldRef:
        fieldPath: metadata.uid

The detector maps K8S_POD_NAME to k8s.pod.name and K8S_POD_UID to k8s.pod.uid. Each attribute is optional and is omitted if its environment variable is missing or empty. Pod identity is only populated when AKS cluster metadata is detected; the pod environment variables alone do not identify AKS. The detector does not infer pod identity from the hostname.

The pod UID identifies the pod, not an individual service instance within it. It remains the same across container restarts within that pod and changes when the pod is replaced. The detector does not set or overwrite service.instance.id, since multiple containers or worker processes can run instances of the same service in one pod. Configure that attribute separately through your SDK resource, OTEL_RESOURCE_ATTRIBUTES with envDetector, or a dedicated service instance ID detector.

import { detectResources } from '@opentelemetry/resources';
import { azureAksDetector } from '@opentelemetry/resource-detector-azure';

const resource = detectResources({
    detectors: [azureAksDetector],
});

const tracerProvider = new NodeTracerProvider({ resource });

Useful links

License

Apache 2.0 - See LICENSE for more information.

Current Tags

  • 0.33.0                                ...           latest (22 days ago)

47 Versions

  • 0.33.0                                ...           22 days ago
  • 0.32.0                                ...           a month ago
  • 0.31.0                                ...           2 months ago
  • 0.30.0                                ...           3 months ago
  • 0.29.0                                ...           4 months ago
  • 0.28.0                                ...           5 months ago
  • 0.27.0                                ...           6 months ago
  • 0.26.0                                ...           6 months ago
  • 0.25.0                                ...           7 months ago
  • 0.24.0                                ...           7 months ago
  • 0.23.0                                ...           7 months ago
  • 0.22.0                                ...           8 months ago
  • 0.21.0                                ...           9 months ago
  • 0.20.0                                ...           9 months ago
  • 0.19.0                                ...           10 months ago
  • 0.18.0                                ...           10 months ago
  • 0.17.0                                ...           a year ago
  • 0.16.0                                ...           a year ago
  • 0.15.0                                ...           a year ago
  • 0.14.0                                ...           a year ago
  • 0.13.2                                ...           a year ago
  • 0.13.1                                ...           a year ago
  • 0.12.0                                ...           a year ago
  • 0.11.0                                ...           a year ago
  • 0.10.0                                ...           a year ago
  • 0.9.0                                ...           a year ago
  • 0.8.0                                ...           2 years ago
  • 0.7.0                                ...           2 years ago
  • 0.6.1                                ...           2 years ago
  • 0.6.0                                ...           2 years ago
  • 0.5.0                                ...           2 years ago
  • 0.4.0                                ...           2 years ago
  • 0.3.0                                ...           2 years ago
  • 0.2.12                                ...           2 years ago
  • 0.2.11                                ...           2 years ago
  • 0.2.10                                ...           2 years ago
  • 0.2.9                                ...           2 years ago
  • 0.2.8                                ...           2 years ago
  • 0.2.7                                ...           3 years ago
  • 0.2.6                                ...           3 years ago
  • 0.2.5                                ...           3 years ago
  • 0.2.4                                ...           3 years ago
  • 0.2.3                                ...           3 years ago
  • 0.2.2                                ...           3 years ago
  • 0.2.1                                ...           3 years ago
  • 0.2.0                                ...           3 years ago
  • 0.1.0                                ...           3 years ago
Downloads
Total 66
Today 0
This Week 0
This Month 61
Last Day 0
Last Week 6
Last Month 0

© 2010 - cnpmjs.org x YWFE | Home | YWFE