Opentelemetry-go: Env var resource errors when env var is not set

Created on 1 Sep 2020  路  3Comments  路  Source: open-telemetry/opentelemetry-go

If OTEL_RESOURCE_ATTRIBUTES has not been set,resource.FromEnv's Detect function (used by resource.Detect) will generate an ErrMissingResource error, causing detection to fail. The failure in that detection isn't entirely clear _which_ resource detection failed, with the aggregate error reporting:

detecting resources: [missing resource]

The specification doesn't make the expected behaviour when the env var isn't populated entirely clear here, but my understanding from the Python implementation is that this is treated as _optional_, and doesn't fail detection:

https://opentelemetry-python.readthedocs.io/en/stable/_modules/opentelemetry/sdk/resources.html

    def detect(self) -> "Resource":
        env_resources_items = os.environ.get("OTEL_RESOURCE_ATTRIBUTES")
        env_resource_map = {}
        if env_resources_items:
            env_resource_map = {
                key.strip(): value.strip()
                for key, value in (
                    item.split("=") for item in env_resources_items.split(",")
                )
            }
        return Resource(env_resource_map)

While any successfully detected resource attributes are returned along with the error, it is at least _unusual_ in Go to use the other values if a call has returned an error (with exemptions for cases like io.EOF)

bug SDK

Most helpful comment

If no one's looking into this, happy to take it :slightly_smiling_face:

All 3 comments

Found in the spec: https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/resource/sdk.md#detecting-resource-information-from-the-environment

Note the failure to detect any resource information MUST NOT be considered an error, whereas an error that occurs during an attempt to detect resource information SHOULD be considered an error.

If no one's looking into this, happy to take it :slightly_smiling_face:

This can be closed as https://github.com/open-telemetry/opentelemetry-go/pull/1170 has been merged, included wrong issue # by accident so the issue wasn't closed automatically. Sorry.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tigrannajaryan picture tigrannajaryan  路  5Comments

MrAlias picture MrAlias  路  7Comments

ThomsonTan picture ThomsonTan  路  3Comments

moorara picture moorara  路  3Comments

MrAlias picture MrAlias  路  4Comments