Copyright | (c) Ian Duncan 2021 |
---|---|
License | BSD-3 |
Maintainer | Ian Duncan |
Stability | experimental |
Portability | non-portable (GHC extensions) |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
A Resource is an immutable representation of the entity producing telemetry. 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.
Synopsis
- mkResource :: [Maybe (Text, Attribute)] -> Resource r
- data Resource (schema :: Maybe Symbol)
- (.=) :: ToAttribute a => Text -> a -> Maybe (Text, Attribute)
- (.=?) :: ToAttribute a => Text -> Maybe a -> Maybe (Text, Attribute)
- type family ResourceMerge (schemaLeft :: Maybe Symbol) (schemaRight :: Maybe Symbol) :: Maybe Symbol where ...
- mergeResources :: Resource new -> Resource old -> Resource (ResourceMerge new old)
- class ToResource a where
- type ResourceSchema a :: Maybe Symbol
- toResource :: a -> Resource (ResourceSchema a)
- class MaterializeResource schema
- materializeResources :: MaterializeResource schema => Resource schema -> MaterializedResources
- data MaterializedResources
- emptyMaterializedResources :: MaterializedResources
- getMaterializedResourcesSchema :: MaterializedResources -> Maybe String
- getMaterializedResourcesAttributes :: MaterializedResources -> Attributes
Creating resources directly
data Resource (schema :: Maybe Symbol) Source #
A set of attributes created from one or more resources.
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.
(.=) :: ToAttribute a => Text -> a -> Maybe (Text, Attribute) Source #
Utility function to convert a required resource attribute
into the format needed for mkResource
.
(.=?) :: ToAttribute a => Text -> Maybe a -> Maybe (Text, Attribute) Source #
Utility function to convert an optional resource attribute
into the format needed for mkResource
.
type family ResourceMerge (schemaLeft :: Maybe Symbol) (schemaRight :: Maybe Symbol) :: Maybe Symbol where ... Source #
Static checks to prevent invalid resources from being merged.
Note: This is intended to be utilized for merging of resources whose attributes come from different sources, such as environment variables, or metadata extracted from the host or container.
The resulting resource will have all attributes that are on any of the two input resources. If a key exists on both the old and updating resource, the value of the updating resource will be picked (even if the updated value is "empty").
The resulting resource will have the Schema URL calculated as follows:
- If the old resource's Schema URL is empty then the resulting resource's Schema URL will be set to the Schema URL of the updating resource,
- Else if the updating resource's Schema URL is empty then the resulting resource's Schema URL will be set to the Schema URL of the old resource,
- Else if the Schema URLs of the old and updating resources are the same then that will be the Schema URL of the resulting resource,
- Else this is a merging error (this is the case when the Schema URL of the old and updating resources are not empty and are different). The resulting resource is therefore statically prohibited by this type-level function.
ResourceMerge 'Nothing a = a | |
ResourceMerge a 'Nothing = a | |
ResourceMerge ('Just s) ('Just s) = 'Just s |
:: Resource new | the updating resource whose attributes take precedence |
-> Resource old | the old resource |
-> Resource (ResourceMerge new old) |
Combine two Resource
values into a new Resource
that contains the
attributes of the two inputs.
See the ResourceMerge
documentation about the additional semantics of merging two resources.
Since: 0.0.1.0
Creating resources from data structures
class ToResource a where Source #
A convenience class for converting arbitrary data into resources.
type ResourceSchema a :: Maybe Symbol Source #
Resource schema (if any) associated with the defined resource
type ResourceSchema a = 'Nothing
toResource :: a -> Resource (ResourceSchema a) Source #
Convert the input value to a Resource
Instances
class MaterializeResource schema Source #
Instances
MaterializeResource ('Nothing :: Maybe Symbol) Source # | |
Defined in OpenTelemetry.Resource | |
KnownSymbol s => MaterializeResource ('Just s) Source # | |
Defined in OpenTelemetry.Resource materializeResources :: Resource ('Just s) -> MaterializedResources Source # |
materializeResources :: MaterializeResource schema => Resource schema -> MaterializedResources Source #
Convert resource fields into a version that discharges the schema from the type level to the runtime level.
Using resources with a TracerProvider
data MaterializedResources Source #
A read-only resource attribute collection with an associated schema.
Instances
Show MaterializedResources Source # | |
Defined in OpenTelemetry.Resource showsPrec :: Int -> MaterializedResources -> ShowS # show :: MaterializedResources -> String # showList :: [MaterializedResources] -> ShowS # | |
Eq MaterializedResources Source # | |
Defined in OpenTelemetry.Resource (==) :: MaterializedResources -> MaterializedResources -> Bool # (/=) :: MaterializedResources -> MaterializedResources -> Bool # |
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