instrument_resource (instrument v1.0.0)

View Source

OpenTelemetry Resource representation.

A Resource describes the entity producing telemetry. It contains attributes that identify the service, host, process, etc.

Example Usage

  %% Create a resource
  Resource = instrument_resource:create(#{
    <<"service.name">> => <<"my-service">>,
    <<"service.version">> => <<"1.0.0">>
  }).
 
  %% Merge resources (later values override)
  Merged = instrument_resource:merge(Resource1, Resource2).
 
  %% Get the default resource (with detectors)
  Default = instrument_resource:default().

Summary

Functions

Creates a resource with the given attributes.

Creates a resource with attributes and schema URL.

Creates a default resource with SDK and detected attributes.

Creates an empty resource.

Gets the attributes from a resource.

Gets the global default resource.

Gets the schema URL from a resource.

Merges two resources. Later resource attributes override earlier ones.

Sets the global default resource.

Functions

create(Attributes)

-spec create(map()) -> #resource{attributes :: map(), schema_url :: binary() | undefined}.

Creates a resource with the given attributes.

create(Attributes, SchemaUrl)

-spec create(map(), binary() | undefined) ->
                #resource{attributes :: map(), schema_url :: binary() | undefined}.

Creates a resource with attributes and schema URL.

default()

-spec default() -> #resource{attributes :: map(), schema_url :: binary() | undefined}.

Creates a default resource with SDK and detected attributes.

empty()

-spec empty() -> #resource{attributes :: map(), schema_url :: binary() | undefined}.

Creates an empty resource.

get_attributes(Resource)

-spec get_attributes(#resource{attributes :: map(), schema_url :: binary() | undefined}) -> map().

Gets the attributes from a resource.

get_default()

-spec get_default() -> #resource{attributes :: map(), schema_url :: binary() | undefined}.

Gets the global default resource.

get_schema_url(Resource)

-spec get_schema_url(#resource{attributes :: map(), schema_url :: binary() | undefined}) ->
                        binary() | undefined.

Gets the schema URL from a resource.

merge(Resource, Resource)

-spec merge(#resource{attributes :: map(), schema_url :: binary() | undefined},
            #resource{attributes :: map(), schema_url :: binary() | undefined}) ->
               #resource{attributes :: map(), schema_url :: binary() | undefined}.

Merges two resources. Later resource attributes override earlier ones.

set_default(Resource)

-spec set_default(#resource{attributes :: map(), schema_url :: binary() | undefined}) -> ok.

Sets the global default resource.