| Copyright | (c) Ian Duncan 2021-2026 |
|---|---|
| License | BSD-3 |
| Stability | experimental |
| Safe Haskell | None |
| Language | Haskell2010 |
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
Synopsis
- mkResource :: [Maybe (Text, Attribute)] -> Resource
- mkResourceWithSchema :: Maybe Text -> [Maybe (Text, Attribute)] -> Resource
- semConvSchemaUrl :: Text
- data Resource
- (.=) :: ToAttribute a => Text -> a -> Maybe (Text, Attribute)
- (.=?) :: ToAttribute a => Text -> Maybe a -> Maybe (Text, Attribute)
- mergeResources :: Resource -> Resource -> Resource
- class ToResource a where
- toResource :: a -> Resource
- data MaterializedResources
- materializeResources :: Resource -> MaterializedResources
- emptyMaterializedResources :: MaterializedResources
- getMaterializedResourcesSchema :: MaterializedResources -> Maybe String
- getMaterializedResourcesAttributes :: MaterializedResources -> Attributes
- materializeResourcesWithSchema :: Maybe String -> Resource -> MaterializedResources
- setMaterializedResourcesSchema :: Maybe String -> MaterializedResources -> MaterializedResources
- getResourceAttributes :: Resource -> Attributes
- getResourceSchemaUrl :: Resource -> Maybe Text
Creating resources directly
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
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
(.=) :: 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
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
Instances
Using resources with a TracerProvider
data MaterializedResources Source #
A read-only resource attribute collection with an associated schema.
Since: 0.0.1.0
Instances
| Show MaterializedResources Source # | |
Defined in OpenTelemetry.Resource Methods showsPrec :: Int -> MaterializedResources -> ShowS # show :: MaterializedResources -> String # showList :: [MaterializedResources] -> ShowS # | |
| Eq MaterializedResources Source # | |
Defined in OpenTelemetry.Resource Methods (==) :: MaterializedResources -> MaterializedResources -> Bool # (/=) :: MaterializedResources -> MaterializedResources -> Bool # | |
materializeResources :: Resource -> MaterializedResources Source #
Convert a Resource to MaterializedResources.
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
getMaterializedResourcesSchema :: MaterializedResources -> Maybe String Source #
Access the schema for a MaterializedResources value.
Since: 0.0.1.0
getMaterializedResourcesAttributes :: MaterializedResources -> Attributes Source #
Access the attributes for a MaterializedResources value.
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