Skip to content

Added OTEL tracing #196

Open
davidigandan wants to merge 20 commits intomainfrom
dev
Open

Added OTEL tracing #196
davidigandan wants to merge 20 commits intomainfrom
dev

Conversation

@davidigandan
Copy link

Added OTEL Tracing to zocalo service

Comment on lines +80 to +83
if isinstance(message, dict):
environment = message.get("environment", {})
if isinstance(environment, dict):
recipe_id = environment.get("ID")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rw is guaranteed to be initialised here, line 105 accesses to get this same data, so probably can be replaced by

recipe_id = rw.environment.get("ID")

or, to taste,

if recipe_id := rw.environment.get("ID"):

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Comment on lines +87 to +89
span.add_event(
"recipe.id_extracted", attributes={"recipe_id": recipe_id}
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we don't need this?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed- fixed

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed-fixed

Comment on lines +97 to +103
log_extra = {
"span_id": span_id,
"trace_id": trace_id,
}

if recipe_id:
log_extra["recipe_id"] = recipe_id
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this currently appears vestigial; did you mean to use log_extender?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it looks like the easiest way to attach this is via log_extender. possibly https://docs.python.org/3/library/contextlib.html#contextlib.ExitStack helps with the possibly-not-present-multiple context managers

license = { text = "BSD-3-Clause" }
requires-python = ">=3.10"
dependencies = ["bidict", "pika", "setuptools", "stomp-py>=7"]
dependencies = ["zocalo","marshmallow","bidict", "pika", "setuptools", "stomp-py>=7", "opentelemetry-api==1.20.0", "opentelemetry-sdk==1.20.0", "opentelemetry-exporter-otlp-proto-http==1.20.0" ]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove zocalo and marshmallow

# Configure OTELTracing if configuration is available
otel_config = (
self.config.opentelemetry
if self.config and hasattr(self.config, "opentelemetry")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like in https://github.com/DiamondLightSource/python-zocalo/blob/b3e3ca4addba6e61fab0bef2fcb825a49e73938a/src/zocalo/configuration/__init__.py#L150 that the name set is _opentelemetry - assuming the self.config object is what we expect

)

if otel_config:
if "endpoint" not in otel_config:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you have already validated these in the configuration.OTEL plugin then you do not need to do so again; also - if you have asked to configure but provided wrong values, this is an error

Comment on lines +239 to +243
except Exception as e:
# Continue without tracing if configuration fails
self.log.warning(
"Failed to configure OpenTelemetry tracing: %s", str(e)
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the user has explicitly requested opentelemetry then failing to configure it should probably be an error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants