hs-opentelemetry-api
Copyright(c) Ian Duncan 2021-2026
LicenseBSD-3
Stabilityexperimental
Safe HaskellNone
LanguageHaskell2010

OpenTelemetry.Resource

Description

Overview

A Resource is an immutable set of attributes describing the entity that produces telemetry: the service name, host, container, cloud environment, etc. Every span, metric, and log record is associated with a resource.

Quick example

import OpenTelemetry.Resource

-- Build a resource from key-value pairs:
myResource :: Resource
myResource = mkResource
  [ "service.name" .= ("my-service" :: Text)
  , "service.version" .= ("1.2.0" :: Text)
  ]

-- Build from a typed data structure:
import OpenTelemetry.Resource.Service
myService :: Resource
myService = toResource Service
  { serviceName = "my-service"
  , serviceNamespace = Just "production"
  , serviceInstanceId = Nothing
  , serviceVersion = Just "1.2.0"
  , serviceCriticality = Nothing
  }

Automatic detection

The SDK automatically detects resources from the environment (hostname, OS, process info, container ID, cloud metadata). You can add your own on top:

(processors, opts) <- getTracerProviderInitializationOptions' myResource

Merging

Resources can be combined with <> or mergeResources. When keys conflict, the first argument (the updating resource) wins. Schema URLs are merged per the OTel spec.

Spec reference

https://opentelemetry.io/docs/specs/otel/resource/sdk/

Synopsis

Creating resources directly

mkResource :: [Maybe (Text, Attribute)] -> Resource Source #

Utility function to create a resource from a list of fields and attributes. See the .= and .=? functions.

Since: 0.0.1.0

mkResourceWithSchema :: Maybe Text -> [Maybe (Text, Attribute)] -> Resource Source #

Create a resource with an explicit schema URL.

Since: 0.4.0.0

semConvSchemaUrl :: Text Source #

The OpenTelemetry semantic conventions schema URL for version 1.40.0. Resources that use semantic convention attributes SHOULD carry this URL so backends can perform automatic attribute migration across versions.

Since: 0.4.0.0

data Resource Source #

A set of attributes with an optional schema URL.

A Resource is an immutable representation of the entity producing telemetry as Attributes. For example, a process producing telemetry that is running in a container on Kubernetes has a Pod name, it is in a namespace and possibly is part of a Deployment which also has a name.

All three of these attributes can be included in the Resource.

Note that there are certain "standard attributes" that have prescribed meanings.

A number of these standard resources may be found in the OpenTelemetry.Resource.* modules.

The primary purpose of resources as a first-class concept in the SDK is decoupling of discovery of resource information from exporters. This allows for independent development and easy customization for users that need to integrate with closed source environments.

Since: 0.0.1.0

Instances

Instances details
Monoid Resource Source # 
Instance details

Defined in OpenTelemetry.Resource

Semigroup Resource Source #

Merge two resources, taking the left-biased union of attributes.

Instance details

Defined in OpenTelemetry.Resource

Show Resource Source # 
Instance details

Defined in OpenTelemetry.Resource

Eq Resource Source # 
Instance details

Defined in OpenTelemetry.Resource

(.=) :: ToAttribute a => Text -> a -> Maybe (Text, Attribute) Source #

Utility function to convert a required resource attribute into the format needed for mkResource.

Since: 0.0.1.0

(.=?) :: ToAttribute a => Text -> Maybe a -> Maybe (Text, Attribute) Source #

Utility function to convert an optional resource attribute into the format needed for mkResource.

Since: 0.0.1.0

mergeResources Source #

Arguments

:: Resource

the updating resource whose attributes take precedence

-> Resource

the old resource

-> Resource 

Combine two Resource values into a new Resource that contains the attributes of the two inputs.

If a key exists on both resources, the value of the first (updating) resource takes precedence.

Schema URL merge follows the OpenTelemetry specification:

  • If one resource's Schema URL is empty, the other's is used.
  • If both are the same, that URL is used.
  • If both are non-empty and different, the first resource's URL is kept (the spec says this case is "implementation-specific"); a warning is also emitted to the OTel diagnostic logger.

Since: 0.0.1.0

Creating resources from data structures

class ToResource a where Source #

A convenience class for converting arbitrary data into resources.

Since: 0.0.1.0

Methods

toResource :: a -> Resource Source #

Convert the input value to a Resource

Instances

Instances details
ToResource Cloud Source # 
Instance details

Defined in OpenTelemetry.Resource.Cloud

ToResource Container Source # 
Instance details

Defined in OpenTelemetry.Resource.Container

ToResource DeploymentEnvironment Source # 
Instance details

Defined in OpenTelemetry.Resource.DeploymentEnvironment

ToResource FaaS Source # 
Instance details

Defined in OpenTelemetry.Resource.FaaS

ToResource Host Source # 
Instance details

Defined in OpenTelemetry.Resource.Host

ToResource Cluster Source # 
Instance details

Defined in OpenTelemetry.Resource.Kubernetes

ToResource Container Source # 
Instance details

Defined in OpenTelemetry.Resource.Kubernetes

ToResource CronJob Source # 
Instance details

Defined in OpenTelemetry.Resource.Kubernetes

ToResource DaemonSet Source # 
Instance details

Defined in OpenTelemetry.Resource.Kubernetes

ToResource Deployment Source # 
Instance details

Defined in OpenTelemetry.Resource.Kubernetes

ToResource Job Source # 
Instance details

Defined in OpenTelemetry.Resource.Kubernetes

ToResource Namespace Source # 
Instance details

Defined in OpenTelemetry.Resource.Kubernetes

ToResource Node Source # 
Instance details

Defined in OpenTelemetry.Resource.Kubernetes

ToResource Pod Source # 
Instance details

Defined in OpenTelemetry.Resource.Kubernetes

ToResource ReplicaSet Source # 
Instance details

Defined in OpenTelemetry.Resource.Kubernetes

ToResource StatefulSet Source # 
Instance details

Defined in OpenTelemetry.Resource.Kubernetes

ToResource OperatingSystem Source # 
Instance details

Defined in OpenTelemetry.Resource.OperatingSystem

ToResource Process Source # 
Instance details

Defined in OpenTelemetry.Resource.Process

ToResource ProcessRuntime Source # 
Instance details

Defined in OpenTelemetry.Resource.Process

ToResource Service Source # 
Instance details

Defined in OpenTelemetry.Resource.Service

ToResource Telemetry Source # 
Instance details

Defined in OpenTelemetry.Resource.Telemetry

ToResource Webengine Source # 
Instance details

Defined in OpenTelemetry.Resource.Webengine

Using resources with a TracerProvider

data MaterializedResources Source #

A read-only resource attribute collection with an associated schema.

Since: 0.0.1.0

emptyMaterializedResources :: MaterializedResources Source #

A placeholder for MaterializedResources when no resource information is available, needed, or required.

Since: 0.0.1.0

Convenience constructors

materializeResourcesWithSchema :: Maybe String -> Resource -> MaterializedResources Source #

Materialize a resource with an explicit runtime schema URL, overriding any schema URL on the resource itself.

let res = materializeResourcesWithSchema
            (Just "https://opentelemetry.io/schemas/1.25.0")
            (mkResource ["service.name" .= ("my-app" :: Text)])

Since: 0.4.0.0

setMaterializedResourcesSchema :: Maybe String -> MaterializedResources -> MaterializedResources Source #

Override the schema URL on an already-materialized resource. Replaces any previously set schema URL.

Since: 0.4.0.0

Accessing resource fields

getResourceAttributes :: Resource -> Attributes Source #

Access the attributes of a resource.

Since: 0.0.1.0

getResourceSchemaUrl :: Resource -> Maybe Text Source #

Access the schema URL of a resource.

Since: 0.0.1.0