-
Notifications
You must be signed in to change notification settings - Fork 2
feat: OTel: Task Processor #197
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -66,7 +66,12 @@ def ensure_cli_env() -> typing.Generator[None, None, None]: | |
| setup_tracing, | ||
| ) | ||
|
|
||
| service_name = env.str("OTEL_SERVICE_NAME", "flagsmith-api") | ||
| default_service_name = ( | ||
| "flagsmith-task-processor" | ||
| if "task-processor" in sys.argv | ||
| else "flagsmith-api" | ||
| ) | ||
|
Comment on lines
+69
to
+73
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thought: Should we just set OTEL_SERVICE_NAME in container settings? I'm tempted to the smaller effort this allows, but it got my eyebrow raised. |
||
| service_name = env.str("OTEL_SERVICE_NAME", default_service_name) | ||
| log_provider = build_otel_log_provider( | ||
| endpoint=f"{otel_endpoint}/v1/logs", | ||
| service_name=service_name, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| # Generated by Django 5.2.12 on 2026-04-10 14:29 | ||
|
|
||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ("task_processor", "0013_add_last_picked_at"), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.AddField( | ||
| model_name="recurringtask", | ||
| name="trace_context", | ||
| field=models.JSONField(blank=True, null=True), | ||
| ), | ||
| migrations.AddField( | ||
| model_name="task", | ||
| name="trace_context", | ||
| field=models.JSONField(blank=True, null=True), | ||
| ), | ||
| ] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -168,3 +168,70 @@ def test_ensure_cli_env__task_processor_in_argv__sets_run_by_processor( | |
| # When / Then | ||
| with ensure_cli_env(): | ||
| assert os.environ.get("RUN_BY_PROCESSOR") == "true" | ||
|
|
||
|
|
||
| def test_ensure_cli_env__task_processor__expected_otel_service_name( | ||
| monkeypatch: pytest.MonkeyPatch, | ||
| mocker: MockerFixture, | ||
| ) -> None: | ||
| # Given | ||
| monkeypatch.setattr("sys.argv", ["flagsmith", "task-processor"]) | ||
| monkeypatch.setenv("OTEL_EXPORTER_OTLP_ENDPOINT", "http://collector:4318") | ||
|
|
||
| mock_build_log = mocker.patch( | ||
| "common.core.otel.build_otel_log_provider", | ||
| return_value=mocker.MagicMock(spec=LoggerProvider), | ||
| ) | ||
| mock_build_tracer = mocker.patch( | ||
| "common.core.otel.build_tracer_provider", | ||
| return_value=mocker.MagicMock(spec=TracerProvider), | ||
| ) | ||
| mocker.patch("common.core.otel.setup_tracing") | ||
|
|
||
| # When | ||
| with ensure_cli_env(): | ||
| pass | ||
|
|
||
| # Then | ||
| mock_build_log.assert_called_once_with( | ||
| endpoint="http://collector:4318/v1/logs", | ||
| service_name="flagsmith-task-processor", | ||
| ) | ||
| mock_build_tracer.assert_called_once_with( | ||
| endpoint="http://collector:4318/v1/traces", | ||
| service_name="flagsmith-task-processor", | ||
| ) | ||
|
Comment on lines
+173
to
+203
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure how the Please, either:
|
||
|
|
||
|
|
||
| def test_ensure_cli_env__env_service_name__expected_otel_service_name( | ||
| monkeypatch: pytest.MonkeyPatch, | ||
| mocker: MockerFixture, | ||
| ) -> None: | ||
| # Given | ||
| monkeypatch.setattr("sys.argv", ["flagsmith", "task-processor"]) | ||
| monkeypatch.setenv("OTEL_EXPORTER_OTLP_ENDPOINT", "http://collector:4318") | ||
| monkeypatch.setenv("OTEL_SERVICE_NAME", "my-custom") | ||
|
|
||
| mock_build_log = mocker.patch( | ||
| "common.core.otel.build_otel_log_provider", | ||
| return_value=mocker.MagicMock(spec=LoggerProvider), | ||
| ) | ||
| mock_build_tracer = mocker.patch( | ||
| "common.core.otel.build_tracer_provider", | ||
| return_value=mocker.MagicMock(spec=TracerProvider), | ||
| ) | ||
| mocker.patch("common.core.otel.setup_tracing") | ||
|
|
||
| # When | ||
| with ensure_cli_env(): | ||
| pass | ||
|
|
||
| # Then | ||
| mock_build_log.assert_called_once_with( | ||
| endpoint="http://collector:4318/v1/logs", | ||
| service_name="my-custom", | ||
| ) | ||
| mock_build_tracer.assert_called_once_with( | ||
| endpoint="http://collector:4318/v1/traces", | ||
| service_name="my-custom", | ||
| ) | ||
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.
Related.