Skip to content

Conversation

@unflxw
Copy link
Contributor

@unflxw unflxw commented Oct 3, 2025

See appsignal/test-setups#341 for a test setup.
Part of #8, https://github.com/appsignal/appsignal-collector/issues/315

Move agent stop to Agent class

The logic to stop the agent was found in the Client class. Move
that to the Agent class instead. This will allow us to noop it out
when the agent is not in use.

Add collector_endpoint config option

Add a configuration option that allows for a collector endpoint to
be provided. When given, AppSignal for Python will not use the agent
binary that is bundled with it, and instead send data to the given
collector endpoint.

Implement this by defining a Binary base class, and swapping the
AppSignal's client Agent with a NoopBinary when the collector
endpoint configuration option is set. This paves the way for defining
a Collector class later on.

Configure OpenTelemetry for collector

Configure the OpenTelemetry resource attributes to provide the
required attributes for the collector to process the data.

Add a new service_name configuration option to provide the service
name that the collector expects.

Since revision is optional, set a placeholder value when it is not
present. Do the same for service_name.

Instrument logging when using the collector

When the collector is used, configure the OpenTelemetry logging SDK.

Add an instrumentation that adds OpenTelemetry's LoggingHandler
to the root logger in Python's built-in logging module. This will
automatically send logs to AppSignal from any loggers that are not
explicitly configured not to propagate to the root logger.

Configure AppSignal's internal logger not to propagate to the root
logger.

Simplify default instrumentation names

The convention of using package names made sense as long as what we
were enabling or disabling mapped cleanly to them. In the logging
case, we're enabling instrumentation for the logging package, but
this instrumentation lives in the opentelemetry.sdk._logs package.
Using that package name, however, is confusing, as someone familiar
with the SDK would think that we're disabling the logs section of the
OpenTelemetry SDK entirely.

Change the default instrumentation names to be the names of the
libraries that they instrument, rather than the module paths of the
modules in which the instrumentations are added. This also makes them
shorter, which I'm sure is nice if you need to specify a couple of
them.

For backwards compatibility, support the name being specified with
an opentelemetry.instrumentation. prefix, which is ignored when
matching the names.

unflxw added 4 commits October 2, 2025 12:47
The logic to stop the agent was found in the `Client` class. Move
that to the `Agent` class instead. This will allow us to noop it out
when the agent is not in use.
Add a configuration option that allows for a collector endpoint to
be provided. When given, AppSignal for Python will not use the agent
binary that is bundled with it, and instead send data to the given
collector endpoint.

Implement this by defining a `Binary` base class, and swapping the
AppSignal's client `Agent` with a `NoopBinary` when the collector
endpoint configuration option is set. This paves the way for defining
a `Collector` class later on.
Configure the OpenTelemetry resource attributes to provide the
required attributes for the collector to process the data.

Add a new `service_name` configuration option to provide the service
name that the collector expects.

Since `revision` is optional, set a placeholder value when it is not
present. Do the same for `service_name`.
When the collector is used, configure the OpenTelemetry logging SDK.

Add an instrumentation that adds OpenTelemetry's `LoggingHandler`
to the root logger in Python's built-in `logging` module. This will
automatically send logs to AppSignal from any loggers that are not
explicitly configured not to propagate to the root logger.

Configure AppSignal's internal logger not to propagate to the root
logger.
@unflxw unflxw requested review from lipskis and tombruijn October 3, 2025 13:25
@unflxw unflxw self-assigned this Oct 3, 2025
@unflxw unflxw added the feature A new feature for this component. label Oct 3, 2025
@backlog-helper
Copy link

backlog-helper bot commented Oct 3, 2025

✔️ All good!

New issue guide | Backlog management | Rules | Feedback

The convention of using package names made sense as long as what we
were enabling or disabling mapped cleanly to them. In the `logging`
case, we're enabling instrumentation for the `logging` package, but
this instrumentation lives in the `opentelemetry.sdk._logs` package.
Using that package name, however, is confusing, as someone familiar
with the SDK would think that we're disabling the logs section of the
OpenTelemetry SDK entirely.

Change the default instrumentation names to be the names of the
libraries that they instrument, rather than the module paths of the
modules in which the instrumentations are added. This also makes them
shorter, which I'm sure is nice if you need to specify a couple of
them.

For backwards compatibility, support the name being specified with
an `opentelemetry.instrumentation.` prefix, which is ignored when
matching the names.
@unflxw unflxw force-pushed the collector-endpoint-logging branch from 643da00 to a9d45a5 Compare October 3, 2025 13:41
@backlog-helper

This comment has been minimized.

Comment on lines -108 to -110
@pytest.fixture(scope="function", autouse=True)
def reset_agent_active_state() -> Any:
agent.active = False
Copy link
Member

Choose a reason for hiding this comment

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

We don't need to reset this anymore between tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think not! There's not an agent global anymore -- instead, each client has its own agent instance. We do reset the global client between tests, so the new one that is initialised should be in a clean state.

@tombruijn
Copy link
Member

@unflxw can you ask this customer to try this change once it's released?

@backlog-helper

This comment has been minimized.

@unflxw
Copy link
Contributor Author

unflxw commented Oct 8, 2025

FYI: Keeping this PR open because I keep finding small things here and there that need improving, as I go through documenting it.

@backlog-helper
Copy link

backlog-helper bot commented Oct 9, 2025


This is a message from the daily scheduled checks.

New issue guide | Backlog management | Rules | Feedback

@unflxw unflxw force-pushed the collector-endpoint-logging branch 2 times, most recently from 375c8e1 to d3a06a9 Compare October 9, 2025 10:01
Implement the following configuration options in the integration,
mapping to the collector-supported, `appsignal.config.`-prefixed
resource attribute of the same name:

- `filter_attributes`
- `filter_function_parameters`
- `filter_request_query_parameters`
- `filter_request_payload`
- `response_headers`
- `send_function_parameters`
- `send_request_query_parameters`
- `send_request_payload`

Additionally, also map the following existing configuration options
in the integrations to resource attributes in the same manner:

- `filter_session_data` (mapped to `filter_request_session_data`)
- `ignore_actions`
- `ignore_errors`
- `ignore_namespaces`
- `request_headers`
- `send_session_data` (mapped to `send_request_session_data`)

When validating the configuration, if the configuration would trigger
the use of the collector, emit a warning about any configuration
options set to non-default values which have no effect when using
the collector. Do the same when the agent would be used for
configuration options that would have no effect when using the agent.
@unflxw unflxw force-pushed the collector-endpoint-logging branch from d3a06a9 to c7ac2bd Compare October 9, 2025 10:09
Prevent OpenTelemetry logs from being captured by the logging
instrumentation and sent to AppSignal.

Only disable the propagation of AppSignal logs to the root logger
when the logging instrumentation is in use.
@unflxw unflxw merged commit b5e0f7b into main Oct 9, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature A new feature for this component.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants