Skip to content
This repository has been archived by the owner. It is now read-only.

Add option to set async and endpoint in enable #153

Merged
merged 2 commits into from Mar 18, 2019
Merged

Add option to set async and endpoint in enable #153

merged 2 commits into from Mar 18, 2019

Conversation

@c-w
Copy link
Contributor

@c-w c-w commented Mar 5, 2019

It's a very common use-case to set up AppInsights telemetry in a project
and customize the telemetry channel to be asynchronous; for example to
transparently integrate AppInsights into an existing daemon, worker
thread or webserver that already uses the logging module. It's currently
tedious if the user always has to write the same code over and over
again to import the AsynchronousQueue, AsynchronousSender,
TelemetryChannel, write them all up, before being able to pass them into
the enable function. As such, this change introduces a new shortcut that
lets the user specify async mode as a high-level concept on the enable
function.

This change simplifies the following code:

from applicationinsights.logging import enable
from applicationinsights.channel import AsynchronousQueue
from applicationinsights.channel import AsynchronousSender
from applicationinsights.channel import TelemetryChannel

sender = AsynchronousSender()
queue = AsynchronousQueue(sender)
channel = TelemetryChannel(queue=queue)

enable('my-instrumentation-key', telemetry_channel=channel)

The new code is much nicer for the user:

from applicationinsights.logging import enable

enable('my-instrumentation-key', async_=True)

As a companion to this new functionality, this change also introduces an
argument that lets the user customize the endpoint to which the
telemetry is being sent:

from applicationinsights.logging import enable

enable('my-instrumentation-key', async_=True, endpoint='http://custom')

Together, the two new arguments raise the enable function to feature
parity with the other high level integrations (e.g. Django or Flask) in
terms of ease of developer use and high-level API.

c-w and others added 2 commits Mar 5, 2019
It's a very common use-case to set up AppInsights telemetry in a project
and customize the telemetry channel to be asynchronous; for example to
transparently integrate AppInsights into an existing daemon, worker
thread or webserver that already uses the logging module. It's currently
tedious if the user always has to write the same code over and over
again to import the AsynchronousQueue, AsynchronousSender,
TelemetryChannel, write them all up, before being able to pass them into
the enable function. As such, this change introduces a new shortcut that
lets the user specify async mode as a high-level concept on the enable
function.

This change simplifies the following code:

```py
from applicationinsights.logging import enable
from applicationinsights.channel import AsynchronousQueue
from applicationinsights.channel import AsynchronousSender
from applicationinsights.channel import TelemetryChannel

sender = AsynchronousSender()
queue = AsynchronousQueue(sender)
channel = TelemetryChannel(queue=queue)

enable('my-instrumentation-key', telemetry_channel=channel)
```

The new code is much nicer for the user:

```py
from applicationinsights.logging import enable

enable('my-instrumentation-key', async_=True)
```

As a companion to this new functionality, this change also introduces an
argument that lets the user customize the endpoint to which the
telemetry is being sent:

```py
from applicationinsights.logging import enable

enable('my-instrumentation-key', async_=True, endpoint='http://custom')
```

Together, the two new arguments raise the enable function to feature
parity with the other high level integrations (e.g. Django or Flask) in
terms of ease of developer use and high-level API.
@SergeyKanzhelev SergeyKanzhelev merged commit 63b1c52 into microsoft:develop Mar 18, 2019
2 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants