Skip to content

[FEATURE] Implement Open Telemetry #66

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

Merged
merged 4 commits into from
Mar 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .idea/currency-quote-wrapper.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1,011 changes: 854 additions & 157 deletions poetry.lock

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "currency-quote"
version = "4.0.2"
version = "5.0.0"
description = "Complete solution for extracting currency pair quotes data. With comprehensive testing, parameter validation, flexible configuration management, Hexagonal Architecture, CI/CD pipelines, code quality tools, and detailed documentation."
authors = ["IvanildoBarauna <[email protected]>"]
readme = "README.md"
Expand Down Expand Up @@ -29,8 +29,9 @@ include = ["currency_quote*"]

[tool.poetry.dependencies]
python = "^3.9"
api-to-dataframe = "^1.3.12"
pytest = "^8.3.4"
api-to-dataframe = "^1.4.0"
otel-wrapper = "^0.0.1"

[tool.poetry.group.dev.dependencies]
coverage = "^7.5.4"
Expand Down
4 changes: 4 additions & 0 deletions src/currency_quote/domain/services/get_currency_quote.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
ValidateCurrencyUseCase,
)
from currency_quote.domain.entities.currency import CurrencyQuote, CurrencyObject
from currency_quote.utils.open_observability import increment_metric


class GetCurrencyQuoteService:
Expand All @@ -15,16 +16,19 @@ def __init__(
self.currency = currency
self.currency_repository = currency_repository

@increment_metric
def last(self) -> List[CurrencyQuote]:
valid_currency = self.validate_currency_code()
last_quote = self.currency_repository(valid_currency).get_last_quote()
return last_quote

@increment_metric
def history(self, reference_date: int) -> List[CurrencyQuote]:
return self.currency_repository(
self.validate_currency_code()
).get_history_quote(reference_date=reference_date)

@increment_metric
def validate_currency_code(self) -> CurrencyObject:
currency_valid_obj = ValidateCurrencyUseCase.execute(self.currency)
return currency_valid_obj
10 changes: 10 additions & 0 deletions src/currency_quote/utils/open_observability.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from otel_wrapper import OpenObservability

metrics_wrapper = OpenObservability(application_name="currency-quote").get_wrapper().metrics()


def increment_metric(func):
def inner(*args, **kwargs):
metrics_wrapper.metric_increment(func.__qualname__, value=1, tags=kwargs)
return func(*args, **kwargs)
return inner