Skip to content

Commit e0ec055

Browse files
feature (#916): Observability (#1398)
* Create TelemetryMiddleware * Refactor TelemetryMiddleware * Optimization TelemetryMiddleware * Refactor TelemetryMiddleware * Change msg type in __call__ * Continue process span while publish * Change nesting and add create span * refactor: mv useless types to TYPE_CHECKING * refactor: add TelemetrySettingsProvider protocol & NATS impl * chore: update distributions * Fixed a typo in PR template * Fixed a typo in ABCBroker: _broker_dependecies to _broker_dependencies * Add TelemetryTestcase * Fix invalid ruff formating * Add telemetry tests, fix kind error * Add metrics test, fix invalid metric error * More specifics in the metrics test * Changed getting a destination to methods * Add Rabbit impl * Ruff format * Remove delivery_tag from publish * Refactor extracting attributes * Ruff format * Add AIOKafka impl * Add Confluent impl * Rename test classes * Add Redis impl * Refactor settings providers import * fix: correct TelemetryMiddlewares batch consuming * Fix spans and metrics ordering in tests, switch Confluent attributes methods * Add MESSAGING_BATCH_MESSAGE_COUNT attribute * Add TestConsume and TestPublish to telemetry tests * refactor: create independant TelemetryMiddleware for each broker * tests: use broker factory instead of fixtures in Consume and Publish test cases * tests: refactor RPC and TestClient testcases * tests: refactor RMQ tests * tests: refactor Kafka tests * tests: NATS subscriber tests with patching * tests: RMQ subscriber tests with patching * tests: refactor Redis tests * tests: refactor Confluent tests * chore: run CI * tests: fix Confluent TestClient tests * tests: fix py3.8 compatibility * lint: fix some mypy * chore: fix CI * tests: fix partition tests * tests: fix partition real broker case * Change supported metrics * Separation of metrics for systems with and without batches * Fix _subscriber_setup_extra merge conflict * Refactor and update metrics tests, fix metrics * Refactor metrics, need batches count in publish * feat: count Redis consuming batch size * lint: fix mypy * Add batch tests, metrics ready * chore: solve main conflicts * fix: correct confluent batch body serialization * Fix opentelemetry redis batch test * lint: correct StreamRoute call annotation * Add docs for OpenTelemetry * docs: add otel page links style * chore: bump version * Refactor docs * docs: fix styles --------- Co-authored-by: Nikita Pastukhov <[email protected]> Co-authored-by: Pastukhov Nikita <[email protected]> Co-authored-by: treaditup <[email protected]>
1 parent c555f0f commit e0ec055

File tree

145 files changed

+3842
-999
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

145 files changed

+3842
-999
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ Please delete options that are not relevant.
2222
- [ ] My changes do not generate any new warnings
2323
- [ ] I have added tests to validate the effectiveness of my fix or the functionality of my new feature
2424
- [ ] Both new and existing unit tests pass successfully on my local environment by running `scripts/test-cov.sh`
25-
- [ ] I have ensured that static analysis tests are passing by running `scripts/static-anaylysis.sh`
25+
- [ ] I have ensured that static analysis tests are passing by running `scripts/static-analysis.sh`
2626
- [ ] I have included code examples to illustrate the modifications

.github/workflows/test.yaml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ jobs:
8484
key: ${{ runner.os }}-python-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-test-v03
8585
- name: Install Dependencies
8686
if: steps.cache.outputs.cache-hit != 'true'
87-
run: pip install .[rabbit,kafka,confluent,nats,redis,testing]
87+
run: pip install .[optionals,testing]
8888
- name: Install Pydantic v1
8989
if: matrix.pydantic-version == 'pydantic-v1'
9090
run: pip install "pydantic>=1.10.0,<2.0.0"
@@ -117,7 +117,7 @@ jobs:
117117
cache-dependency-path: pyproject.toml
118118
- name: Install Dependencies
119119
if: steps.cache.outputs.cache-hit != 'true'
120-
run: pip install .[nats,kafka,confluent,rabbit,redis,testing] orjson
120+
run: pip install .[optionals,testing] orjson
121121
- run: mkdir coverage
122122
- name: Test
123123
run: bash scripts/test.sh -m"(slow and (not nats and not kafka and not confluent and not rabbit and not redis)) or (not nats and not kafka and not confluent and not rabbit and not redis)"
@@ -144,7 +144,7 @@ jobs:
144144
cache-dependency-path: pyproject.toml
145145
- name: Install Dependencies
146146
if: steps.cache.outputs.cache-hit != 'true'
147-
run: pip install .[rabbit,kafka,confluent,nats,redis,testing]
147+
run: pip install .[optionals,testing]
148148
- name: Test
149149
run: bash scripts/test.sh -m "(slow and (not nats and not kafka and not confluent and not rabbit and not redis)) or (not nats and not kafka and not confluent and not rabbit and not redis)"
150150

@@ -161,7 +161,7 @@ jobs:
161161
cache-dependency-path: pyproject.toml
162162
- name: Install Dependencies
163163
if: steps.cache.outputs.cache-hit != 'true'
164-
run: pip install .[rabbit,kafka,confluent,nats,redis,testing]
164+
run: pip install .[optionals,testing]
165165
- name: Test
166166
run: bash scripts/test.sh -m "(slow and (not nats and not kafka and not confluent and not rabbit and not redis)) or (not nats and not kafka and not confluent and not rabbit and not redis)"
167167

@@ -194,7 +194,7 @@ jobs:
194194
cache-dependency-path: pyproject.toml
195195
- name: Install Dependencies
196196
if: steps.cache.outputs.cache-hit != 'true'
197-
run: pip install .[nats,kafka,confluent,rabbit,redis,testing]
197+
run: pip install .[optionals,testing]
198198
- run: mkdir coverage
199199
- name: Test
200200
run: bash scripts/test.sh -m "(slow and kafka) or kafka"
@@ -254,7 +254,7 @@ jobs:
254254
cache-dependency-path: pyproject.toml
255255
- name: Install Dependencies
256256
if: steps.cache.outputs.cache-hit != 'true'
257-
run: pip install .[nats,kafka,confluent,rabbit,redis,testing]
257+
run: pip install .[optionals,testing]
258258
- run: mkdir coverage
259259
- name: Test
260260
run: bash scripts/test.sh -m "(slow and confluent) or confluent"
@@ -303,7 +303,7 @@ jobs:
303303
cache-dependency-path: pyproject.toml
304304
- name: Install Dependencies
305305
if: steps.cache.outputs.cache-hit != 'true'
306-
run: pip install .[nats,kafka,confluent,rabbit,redis,testing]
306+
run: pip install .[optionals,testing]
307307
- run: mkdir coverage
308308
- name: Test
309309
run: bash scripts/test.sh -m "(slow and rabbit) or rabbit"
@@ -352,7 +352,7 @@ jobs:
352352
cache-dependency-path: pyproject.toml
353353
- name: Install Dependencies
354354
if: steps.cache.outputs.cache-hit != 'true'
355-
run: pip install .[nats,kafka,confluent,rabbit,redis,testing]
355+
run: pip install .[optionals,testing]
356356
- run: mkdir coverage
357357
- name: Test
358358
run: bash scripts/test.sh -m "(slow and nats) or nats"
@@ -401,7 +401,7 @@ jobs:
401401
cache-dependency-path: pyproject.toml
402402
- name: Install Dependencies
403403
if: steps.cache.outputs.cache-hit != 'true'
404-
run: pip install .[nats,kafka,confluent,rabbit,redis,testing]
404+
run: pip install .[optionals,testing]
405405
- run: mkdir coverage
406406
- name: Test
407407
run: bash scripts/test.sh -m "(slow and redis) or redis"

docs/docs/SUMMARY.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ search:
4141
- [FastAPI Plugin](getting-started/integrations/fastapi/index.md)
4242
- [Django](getting-started/integrations/django/index.md)
4343
- [CLI commands](getting-started/cli/index.md)
44+
- [OpenTelemetry](getting-started/opentelemetry/index.md)
4445
- [Logging](getting-started/logging.md)
4546
- [Config Management](getting-started/config/index.md)
4647
- [Task Scheduling](scheduling.md)
@@ -439,6 +440,15 @@ search:
439440
- [ConsumerProtocol](api/faststream/confluent/message/ConsumerProtocol.md)
440441
- [FakeConsumer](api/faststream/confluent/message/FakeConsumer.md)
441442
- [KafkaMessage](api/faststream/confluent/message/KafkaMessage.md)
443+
- opentelemetry
444+
- [KafkaTelemetryMiddleware](api/faststream/confluent/opentelemetry/KafkaTelemetryMiddleware.md)
445+
- middleware
446+
- [KafkaTelemetryMiddleware](api/faststream/confluent/opentelemetry/middleware/KafkaTelemetryMiddleware.md)
447+
- provider
448+
- [BaseConfluentTelemetrySettingsProvider](api/faststream/confluent/opentelemetry/provider/BaseConfluentTelemetrySettingsProvider.md)
449+
- [BatchConfluentTelemetrySettingsProvider](api/faststream/confluent/opentelemetry/provider/BatchConfluentTelemetrySettingsProvider.md)
450+
- [ConfluentTelemetrySettingsProvider](api/faststream/confluent/opentelemetry/provider/ConfluentTelemetrySettingsProvider.md)
451+
- [telemetry_attributes_provider_factory](api/faststream/confluent/opentelemetry/provider/telemetry_attributes_provider_factory.md)
442452
- parser
443453
- [AsyncConfluentParser](api/faststream/confluent/parser/AsyncConfluentParser.md)
444454
- publisher
@@ -514,6 +524,15 @@ search:
514524
- [ConsumerProtocol](api/faststream/kafka/message/ConsumerProtocol.md)
515525
- [FakeConsumer](api/faststream/kafka/message/FakeConsumer.md)
516526
- [KafkaMessage](api/faststream/kafka/message/KafkaMessage.md)
527+
- opentelemetry
528+
- [KafkaTelemetryMiddleware](api/faststream/kafka/opentelemetry/KafkaTelemetryMiddleware.md)
529+
- middleware
530+
- [KafkaTelemetryMiddleware](api/faststream/kafka/opentelemetry/middleware/KafkaTelemetryMiddleware.md)
531+
- provider
532+
- [BaseKafkaTelemetrySettingsProvider](api/faststream/kafka/opentelemetry/provider/BaseKafkaTelemetrySettingsProvider.md)
533+
- [BatchKafkaTelemetrySettingsProvider](api/faststream/kafka/opentelemetry/provider/BatchKafkaTelemetrySettingsProvider.md)
534+
- [KafkaTelemetrySettingsProvider](api/faststream/kafka/opentelemetry/provider/KafkaTelemetrySettingsProvider.md)
535+
- [telemetry_attributes_provider_factory](api/faststream/kafka/opentelemetry/provider/telemetry_attributes_provider_factory.md)
517536
- parser
518537
- [AioKafkaParser](api/faststream/kafka/parser/AioKafkaParser.md)
519538
- publisher
@@ -596,6 +615,15 @@ search:
596615
- message
597616
- [NatsBatchMessage](api/faststream/nats/message/NatsBatchMessage.md)
598617
- [NatsMessage](api/faststream/nats/message/NatsMessage.md)
618+
- opentelemetry
619+
- [NatsTelemetryMiddleware](api/faststream/nats/opentelemetry/NatsTelemetryMiddleware.md)
620+
- middleware
621+
- [NatsTelemetryMiddleware](api/faststream/nats/opentelemetry/middleware/NatsTelemetryMiddleware.md)
622+
- provider
623+
- [BaseNatsTelemetrySettingsProvider](api/faststream/nats/opentelemetry/provider/BaseNatsTelemetrySettingsProvider.md)
624+
- [NatsBatchTelemetrySettingsProvider](api/faststream/nats/opentelemetry/provider/NatsBatchTelemetrySettingsProvider.md)
625+
- [NatsTelemetrySettingsProvider](api/faststream/nats/opentelemetry/provider/NatsTelemetrySettingsProvider.md)
626+
- [telemetry_attributes_provider_factory](api/faststream/nats/opentelemetry/provider/telemetry_attributes_provider_factory.md)
599627
- parser
600628
- [BatchParser](api/faststream/nats/parser/BatchParser.md)
601629
- [JsParser](api/faststream/nats/parser/JsParser.md)
@@ -638,6 +666,16 @@ search:
638666
- [PatchedMessage](api/faststream/nats/testing/PatchedMessage.md)
639667
- [TestNatsBroker](api/faststream/nats/testing/TestNatsBroker.md)
640668
- [build_message](api/faststream/nats/testing/build_message.md)
669+
- opentelemetry
670+
- [TelemetryMiddleware](api/faststream/opentelemetry/TelemetryMiddleware.md)
671+
- [TelemetrySettingsProvider](api/faststream/opentelemetry/TelemetrySettingsProvider.md)
672+
- consts
673+
- [MessageAction](api/faststream/opentelemetry/consts/MessageAction.md)
674+
- middleware
675+
- [BaseTelemetryMiddleware](api/faststream/opentelemetry/middleware/BaseTelemetryMiddleware.md)
676+
- [TelemetryMiddleware](api/faststream/opentelemetry/middleware/TelemetryMiddleware.md)
677+
- provider
678+
- [TelemetrySettingsProvider](api/faststream/opentelemetry/provider/TelemetrySettingsProvider.md)
641679
- rabbit
642680
- [ExchangeType](api/faststream/rabbit/ExchangeType.md)
643681
- [RabbitBroker](api/faststream/rabbit/RabbitBroker.md)
@@ -664,6 +702,12 @@ search:
664702
- [RabbitRouter](api/faststream/rabbit/fastapi/router/RabbitRouter.md)
665703
- message
666704
- [RabbitMessage](api/faststream/rabbit/message/RabbitMessage.md)
705+
- opentelemetry
706+
- [RabbitTelemetryMiddleware](api/faststream/rabbit/opentelemetry/RabbitTelemetryMiddleware.md)
707+
- middleware
708+
- [RabbitTelemetryMiddleware](api/faststream/rabbit/opentelemetry/middleware/RabbitTelemetryMiddleware.md)
709+
- provider
710+
- [RabbitTelemetrySettingsProvider](api/faststream/rabbit/opentelemetry/provider/RabbitTelemetrySettingsProvider.md)
667711
- parser
668712
- [AioPikaParser](api/faststream/rabbit/parser/AioPikaParser.md)
669713
- publisher
@@ -748,6 +792,12 @@ search:
748792
- [StreamMessage](api/faststream/redis/message/StreamMessage.md)
749793
- [UnifyRedisDict](api/faststream/redis/message/UnifyRedisDict.md)
750794
- [UnifyRedisMessage](api/faststream/redis/message/UnifyRedisMessage.md)
795+
- opentelemetry
796+
- [RedisTelemetryMiddleware](api/faststream/redis/opentelemetry/RedisTelemetryMiddleware.md)
797+
- middleware
798+
- [RedisTelemetryMiddleware](api/faststream/redis/opentelemetry/middleware/RedisTelemetryMiddleware.md)
799+
- provider
800+
- [RedisTelemetrySettingsProvider](api/faststream/redis/opentelemetry/provider/RedisTelemetrySettingsProvider.md)
751801
- parser
752802
- [RawMessage](api/faststream/redis/parser/RawMessage.md)
753803
- [RedisBatchListParser](api/faststream/redis/parser/RedisBatchListParser.md)
275 KB
Loading

docs/docs/assets/img/simple-trace.png

184 KB
Loading
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
# 0.5 - API
3+
# 2 - Release
4+
# 3 - Contributing
5+
# 5 - Template Page
6+
# 10 - Default
7+
search:
8+
boost: 0.5
9+
---
10+
11+
::: faststream.confluent.opentelemetry.KafkaTelemetryMiddleware
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
# 0.5 - API
3+
# 2 - Release
4+
# 3 - Contributing
5+
# 5 - Template Page
6+
# 10 - Default
7+
search:
8+
boost: 0.5
9+
---
10+
11+
::: faststream.confluent.opentelemetry.middleware.KafkaTelemetryMiddleware
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
# 0.5 - API
3+
# 2 - Release
4+
# 3 - Contributing
5+
# 5 - Template Page
6+
# 10 - Default
7+
search:
8+
boost: 0.5
9+
---
10+
11+
::: faststream.confluent.opentelemetry.provider.BaseConfluentTelemetrySettingsProvider
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
# 0.5 - API
3+
# 2 - Release
4+
# 3 - Contributing
5+
# 5 - Template Page
6+
# 10 - Default
7+
search:
8+
boost: 0.5
9+
---
10+
11+
::: faststream.confluent.opentelemetry.provider.BatchConfluentTelemetrySettingsProvider
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
# 0.5 - API
3+
# 2 - Release
4+
# 3 - Contributing
5+
# 5 - Template Page
6+
# 10 - Default
7+
search:
8+
boost: 0.5
9+
---
10+
11+
::: faststream.confluent.opentelemetry.provider.ConfluentTelemetrySettingsProvider
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
# 0.5 - API
3+
# 2 - Release
4+
# 3 - Contributing
5+
# 5 - Template Page
6+
# 10 - Default
7+
search:
8+
boost: 0.5
9+
---
10+
11+
::: faststream.confluent.opentelemetry.provider.telemetry_attributes_provider_factory
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
# 0.5 - API
3+
# 2 - Release
4+
# 3 - Contributing
5+
# 5 - Template Page
6+
# 10 - Default
7+
search:
8+
boost: 0.5
9+
---
10+
11+
::: faststream.kafka.opentelemetry.KafkaTelemetryMiddleware
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
# 0.5 - API
3+
# 2 - Release
4+
# 3 - Contributing
5+
# 5 - Template Page
6+
# 10 - Default
7+
search:
8+
boost: 0.5
9+
---
10+
11+
::: faststream.kafka.opentelemetry.middleware.KafkaTelemetryMiddleware
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
# 0.5 - API
3+
# 2 - Release
4+
# 3 - Contributing
5+
# 5 - Template Page
6+
# 10 - Default
7+
search:
8+
boost: 0.5
9+
---
10+
11+
::: faststream.kafka.opentelemetry.provider.BaseKafkaTelemetrySettingsProvider
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
# 0.5 - API
3+
# 2 - Release
4+
# 3 - Contributing
5+
# 5 - Template Page
6+
# 10 - Default
7+
search:
8+
boost: 0.5
9+
---
10+
11+
::: faststream.kafka.opentelemetry.provider.BatchKafkaTelemetrySettingsProvider
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
# 0.5 - API
3+
# 2 - Release
4+
# 3 - Contributing
5+
# 5 - Template Page
6+
# 10 - Default
7+
search:
8+
boost: 0.5
9+
---
10+
11+
::: faststream.kafka.opentelemetry.provider.KafkaTelemetrySettingsProvider
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
# 0.5 - API
3+
# 2 - Release
4+
# 3 - Contributing
5+
# 5 - Template Page
6+
# 10 - Default
7+
search:
8+
boost: 0.5
9+
---
10+
11+
::: faststream.kafka.opentelemetry.provider.telemetry_attributes_provider_factory
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
# 0.5 - API
3+
# 2 - Release
4+
# 3 - Contributing
5+
# 5 - Template Page
6+
# 10 - Default
7+
search:
8+
boost: 0.5
9+
---
10+
11+
::: faststream.nats.opentelemetry.NatsTelemetryMiddleware
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
# 0.5 - API
3+
# 2 - Release
4+
# 3 - Contributing
5+
# 5 - Template Page
6+
# 10 - Default
7+
search:
8+
boost: 0.5
9+
---
10+
11+
::: faststream.nats.opentelemetry.middleware.NatsTelemetryMiddleware
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
# 0.5 - API
3+
# 2 - Release
4+
# 3 - Contributing
5+
# 5 - Template Page
6+
# 10 - Default
7+
search:
8+
boost: 0.5
9+
---
10+
11+
::: faststream.nats.opentelemetry.provider.BaseNatsTelemetrySettingsProvider
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
# 0.5 - API
3+
# 2 - Release
4+
# 3 - Contributing
5+
# 5 - Template Page
6+
# 10 - Default
7+
search:
8+
boost: 0.5
9+
---
10+
11+
::: faststream.nats.opentelemetry.provider.NatsBatchTelemetrySettingsProvider
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
# 0.5 - API
3+
# 2 - Release
4+
# 3 - Contributing
5+
# 5 - Template Page
6+
# 10 - Default
7+
search:
8+
boost: 0.5
9+
---
10+
11+
::: faststream.nats.opentelemetry.provider.NatsTelemetrySettingsProvider

0 commit comments

Comments
 (0)