-
Notifications
You must be signed in to change notification settings - Fork 652
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Porting redis instrumentation from contrib repo #595
Porting redis instrumentation from contrib repo #595
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very minor details.
I only concerned about the functional tests, I'm not 100% convinced we should we all functional testing in the same place.
ext/opentelemetry-instrumentation-redis/src/opentelemetry/instrumentation/redis/__init__.py
Outdated
Show resolved
Hide resolved
ext/opentelemetry-instrumentation-redis/src/opentelemetry/instrumentation/redis/patch.py
Outdated
Show resolved
Hide resolved
@@ -23,4 +23,8 @@ services: | |||
POSTGRES_USER: testuser | |||
POSTGRES_PASSWORD: testpassword | |||
POSTGRES_DB: opentelemetry-tests | |||
otredis: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if it is a really good approach to keep the tests of the different frameworks under the same test. What about if I only want to test redis?
Is there a technical limitation to do that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there's no technical limitation. it's not the path currently but we can split them if it makes more sense (i suspect as we have more integration tests, we will need to do this to run tests in parallel)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Besides parallel tests, there is also the case when you only want to run a specific test without downloading and starting the other containers that you don't need.
This could be a little bit complicated to set up, so we can ignore and handle in a follow up PR.
ext/opentelemetry-instrumentation-redis/src/opentelemetry/instrumentation/redis/patch.py
Outdated
Show resolved
Hide resolved
I forgot to say, an entry in the documentation is probably missing as well. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's good to go. Just minor details on the comments, we can ignore the issue about putting all functional tests together and handle it later on.
I installed it, used docker-compose up
in the integration tests folder and run the following script with the auto instrumentation command. I was able to see one span was printed to the console.
opentelemetry-auto-instrumentation redisexample.py
# configure otel related things
from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import (
BatchExportSpanProcessor,
ConsoleSpanExporter,
)
tracer_provider = TracerProvider()
trace.set_tracer_provider(tracer_provider)
exporter = ConsoleSpanExporter()
span_processor = BatchExportSpanProcessor(exporter)
tracer_provider.add_span_processor(span_processor)
# actual example starts here
import random
import redis
random.seed(444)
hats = {f"hat:{random.getrandbits(32)}": i for i in (
{
"color": "black",
"price": 49.99,
"style": "fitted",
"quantity": 1000,
"npurchased": 0,
},
{
"color": "maroon",
"price": 59.99,
"style": "hipster",
"quantity": 500,
"npurchased": 0,
},
{
"color": "green",
"price": 99.99,
"style": "baseball",
"quantity": 200,
"npurchased": 0,
})
}
r = redis.Redis(db=1)
with r.pipeline() as pipe:
for h_id, hat in hats.items():
pipe.hmset(h_id, hat)
pipe.execute()
ext/opentelemetry-ext-docker-tests/tests/redis/test_redis_functional.py
Outdated
Show resolved
Hide resolved
ext/opentelemetry-ext-docker-tests/tests/redis/test_redis_functional.py
Outdated
Show resolved
Hide resolved
ext/opentelemetry-instrumentation-redis/src/opentelemetry/instrumentation/redis/patch.py
Outdated
Show resolved
Hide resolved
Regarding integration tests, shouldn't a check for redis be added to |
Yes, it probably should. I didn't add it because in practice redis is basically available as soon as the container's up |
trace.set_tracer_provider(TracerProvider()) | ||
|
||
# You can patch redis specifically | ||
RedisInstrumentor().instrument(tracer_provider=trace.get_tracer_provider()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the general idea is to omit the tracer_provider
parameter in the basic examples and let it as an advance use case. By default all the integrations should default to trace.get_tracer_provider()
when the tracer provider is not passed.
ext/opentelemetry-instrumentation-redis/src/opentelemetry/instrumentation/redis/__init__.py
Outdated
Show resolved
Hide resolved
ext/opentelemetry-ext-docker-tests/tests/redis/test_redis_functional.py
Outdated
Show resolved
Hide resolved
ext/opentelemetry-instrumentation-redis/src/opentelemetry/instrumentation/redis/patch.py
Outdated
Show resolved
Hide resolved
ext/opentelemetry-instrumentation-redis/src/opentelemetry/instrumentation/redis/patch.py
Outdated
Show resolved
Hide resolved
ext/opentelemetry-instrumentation-redis/src/opentelemetry/instrumentation/redis/patch.py
Outdated
Show resolved
Hide resolved
ext/opentelemetry-instrumentation-redis/src/opentelemetry/instrumentation/redis/util.py
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see this is the first package to use opentelemetry-instrumentation-
for the package/distribution name. Is there a discussion for this somewhere? I see #283, but that's months out of date.
I see there's a mention of this in the SIG notes from 04-09 https://docs.google.com/document/d/1CIMGoIOZ-c3-igzbd6_Pnxx1SjAkjwqoYSUWxPY8XIs/view#heading=h.ul61m6gnh8sm but nothing else. I can change it back if that's preferable. |
Only a slight preference as far as I'm concerned. I'd like to keep the names consistent and either rename all the instrumentation-extensions to |
Integration for PyMySQL. Fixes some documentation as well for other db integrations. Leverages dbapi. Co-authored-by: Mauricio Vásquez <[email protected]>
Co-Authored-By: Diego Hurtado <[email protected]>
I renamed it to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tests look good, and it looks like a faithful port of https://github.com/open-telemetry/opentelemetry-python-contrib/blob/72b40ba5f94c320a1e6beb88971f0b1cb55541db/ddtrace/contrib/redis/patch.py.
There are two options for instrumenting code. The first option is to use | ||
the `opentelemetry-auto-instrumentation` executable which will automatically |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are two options for instrumenting code. The first option is to use | |
the `opentelemetry-auto-instrumentation` executable which will automatically | |
There are two options for instrumenting code. The first option is to use the | |
``opentelemetry-auto-instrumentation`` executable which will automatically |
To fix the sphinx target
ext/opentelemetry-ext-redis/src/opentelemetry/instrumentation/redis/__init__.py
Outdated
Show resolved
Hide resolved
super().setUp() | ||
self.redis_client = redis.Redis(port=6379) | ||
self.redis_client.flushall() | ||
RedisInstrumentor().instrument(tracer_provider=self.tracer_provider) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You want to call instrument
/uninstrument
once per test instead of once for the class?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this way its not instrumenting the call to flushall which resets the redis data after each test.
…redis/__init__.py Co-Authored-By: Chris Kleinknecht <[email protected]>
ext/opentelemetry-ext-redis/src/opentelemetry/instrumentation/redis/__init__.py
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved! Just some minor nits/suggestions. 👍
ext/opentelemetry-ext-docker-tests/tests/redis/test_redis_functional.py
Outdated
Show resolved
Hide resolved
Co-Authored-By: Diego Hurtado <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding the "instrumentation" convention, here's the PR for that:
open-telemetry/opentelemetry-specification#539
I believe it will be approved, just a matter of some work on my part to fix it up :)
Although if we're going to do this, I wonder if we just shouldn't rename them all at once.
) | ||
|
||
self.assertEqual(span.attributes.get("db.instance"), 0) | ||
self.assertEqual( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it worth refactoring some of these assertions into a utility method? there's a lot of identical code with regards to db.instance / url.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good call, refactored.
), | ||
"db.instance": conn_kwargs["db"] or 0, | ||
} | ||
except KeyError: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it worth logging this condition? I guess this is just a quick way of writing that if any params or missing, don't include any of these.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure about logging there, i haven't looked into what conditions would cause those keys to be missing
""" Transform redis conn info into dict """ | ||
try: | ||
return { | ||
"db.type": "redis", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this be added regardless?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, updated the code to set available attributes
Exporter and span handling complexity was increasing due to the Span.parent attribute being either a Span or a SpanContext. As there is no requirement in the specification to have the parent attribute be a Span, removing this complexity and handling. Co-authored-by: Chris Kleinknecht <[email protected]> Co-authored-by: Alex Boten <[email protected]>
* feat(xml-http-request): new plugin for auto instrumentation for xml-http-request * chore: new example for xml-http-request and updated examples structure for web * chore: updating readme * chore: linting * chore: fixing origin for tests * chore: linting * chore: updating to use b3 format from core * chore: updates after reviews * chore: wrong function call * chore: updating attribute names * chore: linting * chore: adding preflight requests, fixing few other issues * chore: adding image to examples, updating readme * chore: forcing async to be true, but propagate rest params * chore: fixing type for open and send function * chore: fixing format for headers * chore: reviews * chore: decrement task count when span exists * chore: changes after review * chore: adding weakmap for keeping information connected with xhr * chore: renaming config param * chore: not needed cast * chore: updating title * chore: refactored xhr, removed tracing dependency, few other issues fixed * chore: reviews * chore: refactored for collecting timing resources * chore: fixes after merging * chore: reviews * chore: reviews Co-authored-by: Mayur Kale <[email protected]>
Porting the existing redis instrumentation from the contrib repo to using the OpenTelemetry API and the OpenTelemetry Auto-instrumentation Instrumentor interface.
Similiar to the sqlalchemy PR, the main thing that will need updating is to remove the patch/unpatch methods once the instrumentor interface changes have been merged.
This is replacing open-telemetry/opentelemetry-python-contrib#21