applicationinsights.channel module¶
SynchronousQueue class¶
-
class
applicationinsights.channel.
SynchronousQueue
(sender, persistence_path='')[source]¶ A synchronous queue for use in conjunction with the
SynchronousSender
. The queue will callsend()
onsender()
when it reachesmax_queue_length()
, or when the consumer callsflush()
.from application_insights.channel import SynchronousQueue queue = SynchronousQueue(None) queue.max_queue_length = 1 queue.put(1)
-
get
()¶ Gets a single item from the queue and returns it. If the queue is empty, this method will return None.
- Returns:
contracts.Envelope
. a telemetry envelope object or None if the queue is empty.
-
put
(item)¶ Adds the passed in item object to the queue and calls
flush()
if the size of the queue is larger thanmax_queue_length()
. This method does nothing if the passed in item is None.- Args:
item (
contracts.Envelope
) item the telemetry envelope object to send to the service.
-
property
max_queue_length
¶ The maximum number of items that will be held by the queue before the queue will call the
flush()
method.- Args:
value (int). the maximum queue length. The minimum allowed value is 1.
- Returns:
int. the maximum queue size. (defaults to: 500)
-
property
sender
¶ The sender that is associated with this queue that this queue will use to send data to the service.
- Returns:
SenderBase
. the sender object.
-
SynchronousSender class¶
-
class
applicationinsights.channel.
SynchronousSender
(service_endpoint_uri=None)[source]¶ A synchronous sender that works in conjunction with the
SynchronousQueue
. The queue will callsend()
on the current instance with the data to send.-
send
(data_to_send)¶ Immediately sends the data passed in to
service_endpoint_uri()
. If the service request fails, the passed in items are pushed back to thequeue()
.- Args:
data_to_send (Array): an array of
contracts.Envelope
objects to send to the service.
-
property
queue
¶ The queue that this sender is draining. While
SenderBase
doesn’t implement any means of doing so, derivations of this class do.
-
property
send_buffer_size
¶ The buffer size for a single batch of telemetry. This is the maximum number of items in a single service request that this sender is going to send.
- Args:
value (int). the maximum number of items in a telemetry batch.
- Returns:
int. the maximum number of items in a telemetry batch.
-
property
send_timeout
¶ Time in seconds that the sender should wait before giving up.
-
property
service_endpoint_uri
¶ The HTTP or HTTPS endpoint that this sender will send data to.
- Args:
value (str). the service endpoint URI.
- Returns:
str. the service endpoint URI.
-
AsynchronousQueue class¶
-
class
applicationinsights.channel.
AsynchronousQueue
(*args, **kwargs)[source]¶ An asynchronous queue for use in conjunction with the
AsynchronousSender
. The queue will notify the sender that it needs to pick up items when it reachesmax_queue_length()
, or when the consumer callsflush()
via theflush_notification()
event.-
flush
()[source]¶ Flushes the current queue by notifying the
sender()
via theflush_notification()
event.
-
get
()¶ Gets a single item from the queue and returns it. If the queue is empty, this method will return None.
- Returns:
contracts.Envelope
. a telemetry envelope object or None if the queue is empty.
-
put
(item)[source]¶ Adds the passed in item object to the queue and notifies the
sender()
to start an asynchronous send operation by callingstart()
.- Args:
item (
contracts.Envelope
) the telemetry envelope object to send to the service.
-
property
flush_notification
¶ The flush notification
Event
that thesender()
will use to get notified that a flush is needed.- Returns:
Event
. object that thesender()
can wait on.
-
property
max_queue_length
¶ The maximum number of items that will be held by the queue before the queue will call the
flush()
method.- Args:
value (int). the maximum queue length. The minimum allowed value is 1.
- Returns:
int. the maximum queue size. (defaults to: 500)
-
property
sender
¶ The sender that is associated with this queue that this queue will use to send data to the service.
- Returns:
SenderBase
. the sender object.
-
AsynchronousSender class¶
-
class
applicationinsights.channel.
AsynchronousSender
(service_endpoint_uri=None)[source]¶ An asynchronous sender that works in conjunction with the
AsynchronousQueue
. The sender object will start a worker thread that will pull items from thequeue()
. The thread will be created when the client callsstart()
and will check for queue items everysend_interval()
seconds. The worker thread can also be forced to check the queue by setting theflush_notification()
event.If no items are found, the thread will go back to sleep.
If items are found, the worker thread will send items to the specified service in batches of
send_buffer_size()
.
If no queue items are found for
send_time()
seconds, the worker thread will shut down (andstart()
will need to be called again).-
send
(data_to_send)¶ Immediately sends the data passed in to
service_endpoint_uri()
. If the service request fails, the passed in items are pushed back to thequeue()
.- Args:
data_to_send (Array): an array of
contracts.Envelope
objects to send to the service.
-
property
queue
¶ The queue that this sender is draining. While
SenderBase
doesn’t implement any means of doing so, derivations of this class do.
-
property
send_buffer_size
¶ The buffer size for a single batch of telemetry. This is the maximum number of items in a single service request that this sender is going to send.
- Args:
value (int). the maximum number of items in a telemetry batch.
- Returns:
int. the maximum number of items in a telemetry batch.
-
property
send_interval
¶ The time span in seconds at which the the worker thread will check the
queue()
for items (defaults to: 1.0).- Args:
value (int) the interval in seconds.
- Returns:
int. the interval in seconds.
-
property
send_time
¶ The time span in seconds at which the the worker thread will check the
queue()
for items (defaults to: 1.0).- Args:
value (int) the interval in seconds.
- Returns:
int. the interval in seconds.
-
property
send_timeout
¶ Time in seconds that the sender should wait before giving up.
-
property
service_endpoint_uri
¶ The HTTP or HTTPS endpoint that this sender will send data to.
- Args:
value (str). the service endpoint URI.
- Returns:
str. the service endpoint URI.
QueueBase class¶
-
class
applicationinsights.channel.
QueueBase
(sender, persistence_path='')[source]¶ The base class for all types of queues for use in conjunction with an implementation of
SenderBase
.The queue will notify the sender that it needs to pick up items when it reaches
max_queue_length()
, or when the consumer callsflush()
.-
flush
()[source]¶ Flushes the current queue by notifying the {#sender}. This method needs to be overridden by a concrete implementations of the queue class.
-
get
()[source]¶ Gets a single item from the queue and returns it. If the queue is empty, this method will return None.
- Returns:
contracts.Envelope
. a telemetry envelope object or None if the queue is empty.
-
put
(item)[source]¶ Adds the passed in item object to the queue and calls
flush()
if the size of the queue is larger thanmax_queue_length()
. This method does nothing if the passed in item is None.- Args:
item (
contracts.Envelope
) item the telemetry envelope object to send to the service.
-
property
max_queue_length
¶ The maximum number of items that will be held by the queue before the queue will call the
flush()
method.- Args:
value (int). the maximum queue length. The minimum allowed value is 1.
- Returns:
int. the maximum queue size. (defaults to: 500)
-
property
sender
¶ The sender that is associated with this queue that this queue will use to send data to the service.
- Returns:
SenderBase
. the sender object.
-
SenderBase class¶
-
class
applicationinsights.channel.
SenderBase
(service_endpoint_uri)[source]¶ The base class for all types of senders for use in conjunction with an implementation of
QueueBase
.The queue will notify the sender that it needs to pick up items. The concrete sender implementation will listen to these notifications and will pull items from the queue getting at most
send_buffer_size()
items. It will then callsend()
using the list of items pulled from the queue.-
send
(data_to_send)[source]¶ Immediately sends the data passed in to
service_endpoint_uri()
. If the service request fails, the passed in items are pushed back to thequeue()
.- Args:
data_to_send (Array): an array of
contracts.Envelope
objects to send to the service.
-
property
queue
¶ The queue that this sender is draining. While
SenderBase
doesn’t implement any means of doing so, derivations of this class do.
-
property
send_buffer_size
¶ The buffer size for a single batch of telemetry. This is the maximum number of items in a single service request that this sender is going to send.
- Args:
value (int). the maximum number of items in a telemetry batch.
- Returns:
int. the maximum number of items in a telemetry batch.
-
property
send_timeout
¶ Time in seconds that the sender should wait before giving up.
-
property
service_endpoint_uri
¶ The HTTP or HTTPS endpoint that this sender will send data to.
- Args:
value (str). the service endpoint URI.
- Returns:
str. the service endpoint URI.
-
TelemetryChannel class¶
-
class
applicationinsights.channel.TelemetryChannel.
TelemetryChannel
(context=None, queue=None)[source]¶ The telemetry channel is responsible for constructing a
contracts.Envelope
object from the passed in data and specified telemetry context.from application_insights.channel import TelemetryChannel, contracts channel = TelemetryChannel() event = contracts.EventData() event.name = 'My event' channel.write(event)
-
write
(data, context=None)[source]¶ Enqueues the passed in data to the
queue()
. If the caller specifies a context as well, it will take precedence over the instance incontext()
.- Args:
- data (object). data the telemetry data to send. This will be wrapped in an
contracts.Envelope
before being enqueued to the
queue()
.- context (
TelemetryContext
). context the override context to use when constructing the contracts.Envelope
.
- data (object). data the telemetry data to send. This will be wrapped in an
-
property
context
¶ The context associated with this channel. All
contracts.Envelope
objects created by this channel will use this value if it’s present or if none is specified as part of thewrite()
call.- Returns:
(
TelemetryContext
). the context instance (defaults to: TelemetryContext())
-
property
queue
¶ The queue associated with this channel. All
contracts.Envelope
objects created by this channel will be pushed to this queue.- Returns:
(
QueueBase
). the queue instance (defaults to: SynchronousQueue())
-
property
sender
¶ The sender associated with this channel. This instance will be used to transmit telemetry to the service.
- Returns:
(
SenderBase
). the sender instance (defaults to: SynchronousSender())
-
TelemetryContext class¶
-
class
applicationinsights.channel.
TelemetryContext
[source]¶ Represents the context for sending telemetry to the Application Insights service.
context = TelemetryContext() context.instrumentation_key = '<YOUR INSTRUMENTATION KEY GOES HERE>' context.application.ver = '1.2.3' context.device.id = 'My current device' context.device.oem_name = 'Asus' context.device.model = 'X31A' context.device.type = "Other" context.user.id = 'santa@northpole.net' track_trace('My trace with context')
-
property
properties
¶ The property context. This contains free-form properties that you can add to your telemetry.
- Returns:
(dict). the context object.
-
property