Skip to content

Instantly share code, notes, and snippets.

@SuyogSoti
Last active July 24, 2019 18:11
Show Gist options
  • Save SuyogSoti/3b1d8b22f40eb3c1f34300a0565db55e to your computer and use it in GitHub Desktop.
Save SuyogSoti/3b1d8b22f40eb3c1f34300a0565db55e to your computer and use it in GitHub Desktop.
Distributed Tracing for Azure SDK

Distributed Tracing for Preview 2

There are two different levels of confusion and the behavior should be highlighted for both of them.

When does the SDK enable Tracing?

There are 7 high level scenarios to consider on when we should enable distributed tracing in the SDK libraries.

To be clear, a default implementation is one where we ship the plugin with azure.core. An example of a tracing implementation is OpenCensus.

Also to be clear, by current span context, I am always referring to the span context at the runtime and not the span context in a message.

Customer Action Spans? Header?
The customer does not have any implementations installed and does not specify an implementation via the settings. No No
The customer does have a default tracing implementation installed but does not import it. The customer does not specify an implementation via the settings. No No
The customer does have a default tracing implementation installed but does not import it. The customer does specifies an implementation via the settings. Yes Yes
The customer does have a default tracing implementation installed and imported. That implementation is not OpenCensus. The customer does not specify an implementation via the settings. No No
The customer does have OpenCensus installed and imported. The customer does not specify an implementation via the settings. Yes Yes
The customer does not have any implementations installed but specifies an implementation via the settings by passing in their own plugin. Yes Yes
The customer has settings such that tracing should happen, however they specify that they only want to propagate the headers and not trace. No Yes

To be clear the implementation the customer specifies through the settings takes first priority.

What are the behaviors of the 3 different types of HTTP requests?

The three request types are a regular request, paging and long running operations. The following is how the trace should look for all of them as of Preview 2.

The code that the customer should have to write to generate the trace and the trace exported to json is in the same gist.

Regular Requests

An example of a regular request is when the user does a keyclient.create_key using keyvault. There should be a span created for the method and a span for every network request. In case of retries, we should see each retry as a span.

If a request fails we see a clear retry span as in the following.

image

The each http request spans should have the following labels:

  • http.method
  • http.status_code
  • http.url
  • http.user_agent
  • component
  • x-ms-client-request-id
  • x-ms-request-id

An example is shown with the exact label names below.

1563515220069

Each http request header should have the span context. The actual standard of propagation depends on the implementation.

Paging

Paging is a little bit more interesting because the SDK makes the request lazily. An example of paging is keyclient.list_keys which returns an iterator without making a network request. Each time the customer iterates and there are more keys in the next page, the SDK should fetch. Therefore, there should be a span for the top level function that does not make any network calls. There should then also be a span for each of the network call made for each page. There should, however, not be an overarching parent span for them. An example of such a trace is shown below.

1563515380052

As it can be seen from the trace, the is keyclient.list_keys calls is another function and neither of them make network calls. Because the customer implicitly triggers the network call to fetch the next page, they fetching happen at different places. Before the customer fetches the first page and the rest of the pages, they take a tenth of a second to do something and that behavior is well represented in the trace.

In later previews, each span that represents a network call for fetching pages would be linked to the original trigger function. In the example above, that would be keyclient.list_keys. In preview 2, this feature will not be there.

The span attributes for spans that represent network calls are to be the same as those for regular requests.

Polling/Long Running Operations

This type of request are those where the SDK customer asks a service to do an action that takes a signification amount of time. The server will then return to the SDK with a "check back later". That will initiate a series to polling to check the status of the original long running operation. An example of such an operation is to be done with fileclient.copy_file_from_url for azure.storage.files. For such cases there should be a span created for every network request. That means, there should be a span whenever the status is queried by the polling method. If the SDK customer calls the waiting method, there should be a span created for the duration of that method. An example of such can be seen below.

image

It can be seen clearly that in this particular case, after that initial call, there was wait called and then the user received the resource after a final bit of polling. In the future, the spans related to a single polling instance would be linked, but not for preview 2.

The span attributes for spans that represent network calls are to be the same as those for regular requests.

Lifetime of messages

There are two cases where tracing the lifetime of the message could be interesting. They are in Eventhub and in Storage Queues. Eventhub uses AMQP which has some sort of metadata defined that is able to store the span context from the time it was created. For AMQP there are 2 different schemes defined, annotations and properties, and the community has yet to reach a consensus for where the span context should be attached. The messages in Storage Queues could be arbitrary bytes which have no standard metadata information. This means for both cases, there will be no support to trace the lifetime of the message as of preview 2.

When the specs for Eventhub are defined, then it is important to consider how the lifetime of the messages should be traced. For individual messages, it is easy. All that has to be done for sending is we attach the current span context to the message. When an individual message is received, the span context from that message is linked to the current span context of the SDK. The problem arises when we consider receiving batch messages. For sending, we could put the current span context in the metadata for every message. For receiving, batch messages, there are two things to consider.

  1. The first is that there is a cost to trying to parse the span context from the headers. That cost becomes large when there might be millions of messages to parse.
  2. The second is the case where each message in the batch has a different span context. Let us say that the messages all have a number and the SDK customer is trying to average them. What should the trace behavior be. In the SDK, if there were no cost to parsing the span context and linking, each span context from each message could be linked to the current span context in the SDK.
[
{
"traceId": "bf0f9e569a19916dfacfaa4377a95c99",
"parentId": "b3b220147e092ed6",
"id": "49c842172a47cf39",
"kind": "CLIENT",
"name": "/share/myfile.txt",
"timestamp": 1563949445566126,
"duration": 1599679,
"localEndpoint": {
"serviceName": "suyog-azure-core-v0.01-opencensus",
"port": 9411
},
"tags": {
"component": "http",
"http.method": "PUT",
"http.status_code": "202",
"http.url": "https://distributedtracingsuyog.file.core.windows.net/share/myfile.txt",
"http.user_agent": "azsdk-python-storage-file/12.0.0b1 Python/3.7.3 (Windows-10-10.0.18362-SP0)",
"x-ms-client-request-id": "a3002bb6-addb-11e9-977f-b831b59ea690",
"x-ms-request-id": "945cb7cd-e01a-010d-13e8-41deb5000000"
}
},
{
"traceId": "bf0f9e569a19916dfacfaa4377a95c99",
"parentId": "b51fa2a7c0b5b656",
"id": "b3b220147e092ed6",
"name": "fileclient.copy_file_from_url",
"timestamp": 1563949445561124,
"duration": 1616715,
"localEndpoint": {
"serviceName": "suyog-azure-core-v0.01-opencensus",
"port": 9411
}
},
{
"traceId": "bf0f9e569a19916dfacfaa4377a95c99",
"parentId": "0614b323f416715c",
"id": "7ab6d64a9c8a6332",
"name": "copystatuspoller.wait",
"timestamp": 1563949447183804,
"localEndpoint": {
"serviceName": "suyog-azure-core-v0.01-opencensus",
"port": 9411
}
},
{
"traceId": "bf0f9e569a19916dfacfaa4377a95c99",
"parentId": "2ac0f29c1eff700a",
"id": "a9e5d3240a2632a6",
"kind": "CLIENT",
"name": "/share/myfile.txt",
"timestamp": 1563949447189805,
"duration": 270881,
"localEndpoint": {
"serviceName": "suyog-azure-core-v0.01-opencensus",
"port": 9411
},
"tags": {
"component": "http",
"http.method": "HEAD",
"http.status_code": "200",
"http.url": "https://distributedtracingsuyog.file.core.windows.net/share/myfile.txt",
"http.user_agent": "azsdk-python-storage-file/12.0.0b1 Python/3.7.3 (Windows-10-10.0.18362-SP0)",
"x-ms-client-request-id": "a3f813ca-addb-11e9-b8d9-b831b59ea690",
"x-ms-request-id": "945cb7d0-e01a-010d-14e8-41deb5000000"
}
},
{
"traceId": "bf0f9e569a19916dfacfaa4377a95c99",
"parentId": "0614b323f416715c",
"id": "2ac0f29c1eff700a",
"name": "copyfilepolling.resource",
"timestamp": 1563949447189805,
"duration": 276951,
"localEndpoint": {
"serviceName": "suyog-azure-core-v0.01-opencensus",
"port": 9411
}
},
{
"traceId": "bf0f9e569a19916dfacfaa4377a95c99",
"parentId": "b51fa2a7c0b5b656",
"id": "0614b323f416715c",
"name": "copystatuspoller.result",
"timestamp": 1563949447183637,
"duration": 289230,
"localEndpoint": {
"serviceName": "suyog-azure-core-v0.01-opencensus",
"port": 9411
}
},
{
"traceId": "bf0f9e569a19916dfacfaa4377a95c99",
"id": "b51fa2a7c0b5b656",
"name": "parent",
"timestamp": 1563949445555134,
"duration": 1923679,
"localEndpoint": {
"serviceName": "suyog-azure-core-v0.01-opencensus",
"port": 9411
}
}
]
from azure.storage.file import FileClient
from opencensus.ext.zipkin.trace_exporter import ZipkinExporter
from opencensus.trace.samplers import AlwaysOnSampler
from opencensus.trace import tracer as tracer_module
connection_string = "PLEASE INSERT YOUR CONNECTION STRING HERE"
file = FileClient.from_connection_string(connection_string, share="share", file_path="myfile.txt")
zipExportInst = ZipkinExporter(service_name="suyog-azure-core-v0.01-opencensus", host_name="localhost", port=9411)
tracer = tracer_module.Tracer(sampler=AlwaysOnSampler(), exporter=zipExportInst)
with tracer.span("parent") as parent:
poller = file.copy_file_from_url("https://distributedtracingsuyog.file.core.windows.net/share/myfile.txt")
data = poller.result()
print(data)
tracer.finish()
[
{
"traceId": "018ffaf73ff69a6c5187d76b1af52d89",
"parentId": "3d0fa66758bf4d4e",
"id": "9628192cb7ed80a7",
"kind": "CLIENT",
"name": "/keys/key-0/create",
"timestamp": 1563911358499028,
"duration": 447993,
"localEndpoint": {
"serviceName": "suyog-azure-core-v0.01-opencensus",
"port": 9411
},
"tags": {
"component": "http",
"http.method": "POST",
"http.status_code": "401",
"http.url": "https://susoti-vault.vault.azure.net/keys/key-0/create?api-version=7.0",
"http.user_agent": "python/3.7.3 (Windows-10-10.0.18362-SP0) azure-core/1.0.0b2 azsdk-python-azure-keyvault/7.0",
"x-ms-client-request-id": "f556f166-ad82-11e9-a60c-b831b59ea690",
"x-ms-request-id": "d9bffcda-7d3c-4f9a-b302-8656f31cfa99"
}
},
{
"traceId": "018ffaf73ff69a6c5187d76b1af52d89",
"parentId": "84e3ed271e67465f",
"id": "7fa22940d83c6499",
"kind": "CLIENT",
"name": "/72f988bf-86f1-41af-91ab-2d7cd011db47/oauth2/v2.0/token",
"timestamp": 1563911358962018,
"duration": 405062,
"localEndpoint": {
"serviceName": "suyog-azure-core-v0.01-opencensus",
"port": 9411
},
"tags": {
"component": "http",
"http.method": "POST",
"http.status_code": "200",
"http.url": "https://login.microsoftonline.com/72f988bf-86f1-41af-91ab-2d7cd011db47/oauth2/v2.0/token",
"x-ms-request-id": "7499ee28-a30e-441f-8490-65cbccf81e00"
}
},
{
"traceId": "018ffaf73ff69a6c5187d76b1af52d89",
"parentId": "f913a8445e244b1a",
"id": "84e3ed271e67465f",
"name": "clientsecretcredential.get_token",
"timestamp": 1563911358962018,
"duration": 410034,
"localEndpoint": {
"serviceName": "suyog-azure-core-v0.01-opencensus",
"port": 9411
}
},
{
"traceId": "018ffaf73ff69a6c5187d76b1af52d89",
"parentId": "2ecacb7af82686d2",
"id": "f913a8445e244b1a",
"name": "environmentcredential.get_token",
"timestamp": 1563911358962018,
"duration": 414039,
"localEndpoint": {
"serviceName": "suyog-azure-core-v0.01-opencensus",
"port": 9411
}
},
{
"traceId": "018ffaf73ff69a6c5187d76b1af52d89",
"parentId": "3d0fa66758bf4d4e",
"id": "2ecacb7af82686d2",
"name": "defaultazurecredential.get_token",
"timestamp": 1563911358962018,
"duration": 417059,
"localEndpoint": {
"serviceName": "suyog-azure-core-v0.01-opencensus",
"port": 9411
}
},
{
"traceId": "018ffaf73ff69a6c5187d76b1af52d89",
"parentId": "3d0fa66758bf4d4e",
"id": "94677e02b1d0e85f",
"kind": "CLIENT",
"name": "/keys/key-0/create",
"timestamp": 1563911359383022,
"duration": 180029,
"localEndpoint": {
"serviceName": "suyog-azure-core-v0.01-opencensus",
"port": 9411
},
"tags": {
"component": "http",
"http.method": "POST",
"http.status_code": "200",
"http.url": "https://susoti-vault.vault.azure.net/keys/key-0/create?api-version=7.0",
"http.user_agent": "python/3.7.3 (Windows-10-10.0.18362-SP0) azure-core/1.0.0b2 azsdk-python-azure-keyvault/7.0",
"x-ms-client-request-id": "f556f166-ad82-11e9-a60c-b831b59ea690",
"x-ms-request-id": "d140c5a6-893c-4123-8af5-9217647221ee"
}
},
{
"traceId": "018ffaf73ff69a6c5187d76b1af52d89",
"parentId": "37514dc26cea2fe7",
"id": "3d0fa66758bf4d4e",
"name": "keyclient.create_key",
"timestamp": 1563911358491020,
"duration": 1075997,
"localEndpoint": {
"serviceName": "suyog-azure-core-v0.01-opencensus",
"port": 9411
}
},
{
"traceId": "018ffaf73ff69a6c5187d76b1af52d89",
"parentId": "247f1fb3df82f995",
"id": "beb3a8218b45bf7d",
"name": "clientsecretcredential.get_token",
"timestamp": 1563911359572017,
"localEndpoint": {
"serviceName": "suyog-azure-core-v0.01-opencensus",
"port": 9411
}
},
{
"traceId": "018ffaf73ff69a6c5187d76b1af52d89",
"parentId": "d9edc6d940cbdf12",
"id": "247f1fb3df82f995",
"name": "environmentcredential.get_token",
"timestamp": 1563911359572017,
"duration": 3004,
"localEndpoint": {
"serviceName": "suyog-azure-core-v0.01-opencensus",
"port": 9411
}
},
{
"traceId": "018ffaf73ff69a6c5187d76b1af52d89",
"parentId": "21815405912dbf76",
"id": "d9edc6d940cbdf12",
"name": "defaultazurecredential.get_token",
"timestamp": 1563911359571017,
"duration": 8000,
"localEndpoint": {
"serviceName": "suyog-azure-core-v0.01-opencensus",
"port": 9411
}
},
{
"traceId": "018ffaf73ff69a6c5187d76b1af52d89",
"parentId": "37514dc26cea2fe7",
"id": "21815405912dbf76",
"name": "keyclient.create_key",
"timestamp": 1563911359571017,
"duration": 295000,
"localEndpoint": {
"serviceName": "suyog-azure-core-v0.01-opencensus",
"port": 9411
}
},
{
"traceId": "018ffaf73ff69a6c5187d76b1af52d89",
"parentId": "21815405912dbf76",
"id": "291d6bac3d52a3c5",
"kind": "CLIENT",
"name": "/keys/key-1/create",
"timestamp": 1563911359583060,
"duration": 278991,
"localEndpoint": {
"serviceName": "suyog-azure-core-v0.01-opencensus",
"port": 9411
},
"tags": {
"component": "http",
"http.method": "POST",
"http.status_code": "200",
"http.url": "https://susoti-vault.vault.azure.net/keys/key-1/create?api-version=7.0",
"http.user_agent": "python/3.7.3 (Windows-10-10.0.18362-SP0) azure-core/1.0.0b2 azsdk-python-azure-keyvault/7.0",
"x-ms-client-request-id": "f5faaae2-ad82-11e9-829e-b831b59ea690",
"x-ms-request-id": "7cd6d878-6505-46c4-959c-eac2311a282d"
}
},
{
"traceId": "018ffaf73ff69a6c5187d76b1af52d89",
"parentId": "37514dc26cea2fe7",
"id": "7d387e28276f3988",
"name": "keyclient.list_keys",
"timestamp": 1563911359870059,
"localEndpoint": {
"serviceName": "suyog-azure-core-v0.01-opencensus",
"port": 9411
}
},
{
"traceId": "018ffaf73ff69a6c5187d76b1af52d89",
"parentId": "be046526dd511337",
"id": "37576aeb760ff641",
"name": "clientsecretcredential.get_token",
"timestamp": 1563911359875017,
"localEndpoint": {
"serviceName": "suyog-azure-core-v0.01-opencensus",
"port": 9411
}
},
{
"traceId": "018ffaf73ff69a6c5187d76b1af52d89",
"parentId": "e42bc1965a27daaf",
"id": "be046526dd511337",
"name": "environmentcredential.get_token",
"timestamp": 1563911359875017,
"duration": 4000,
"localEndpoint": {
"serviceName": "suyog-azure-core-v0.01-opencensus",
"port": 9411
}
},
{
"traceId": "018ffaf73ff69a6c5187d76b1af52d89",
"parentId": "79b725af8945fb61",
"id": "e42bc1965a27daaf",
"name": "defaultazurecredential.get_token",
"timestamp": 1563911359875017,
"duration": 8036,
"localEndpoint": {
"serviceName": "suyog-azure-core-v0.01-opencensus",
"port": 9411
}
},
{
"traceId": "018ffaf73ff69a6c5187d76b1af52d89",
"parentId": "79b725af8945fb61",
"id": "fd0e411507b8192c",
"kind": "CLIENT",
"name": "/keys",
"timestamp": 1563911359887017,
"duration": 375035,
"localEndpoint": {
"serviceName": "suyog-azure-core-v0.01-opencensus",
"port": 9411
},
"tags": {
"component": "http",
"http.method": "GET",
"http.status_code": "200",
"http.url": "https://susoti-vault.vault.azure.net/keys?maxresults=10&api-version=7.0",
"http.user_agent": "python/3.7.3 (Windows-10-10.0.18362-SP0) azure-core/1.0.0b2 azsdk-python-azure-keyvault/7.0",
"x-ms-client-request-id": "f628e6d4-ad82-11e9-98ad-b831b59ea690",
"x-ms-request-id": "7c36f3d2-e925-43b4-8e2c-528268914daf"
}
},
{
"traceId": "018ffaf73ff69a6c5187d76b1af52d89",
"parentId": "37514dc26cea2fe7",
"id": "79b725af8945fb61",
"name": "first page",
"timestamp": 1563911359874018,
"duration": 394002,
"localEndpoint": {
"serviceName": "suyog-azure-core-v0.01-opencensus",
"port": 9411
}
},
{
"traceId": "018ffaf73ff69a6c5187d76b1af52d89",
"parentId": "f6c3113e34b947dc",
"id": "b5587c167cf001cb",
"name": "clientsecretcredential.get_token",
"timestamp": 1563911360275020,
"localEndpoint": {
"serviceName": "suyog-azure-core-v0.01-opencensus",
"port": 9411
}
},
{
"traceId": "018ffaf73ff69a6c5187d76b1af52d89",
"parentId": "c2672657d8240228",
"id": "f6c3113e34b947dc",
"name": "environmentcredential.get_token",
"timestamp": 1563911360275020,
"duration": 5998,
"localEndpoint": {
"serviceName": "suyog-azure-core-v0.01-opencensus",
"port": 9411
}
},
{
"traceId": "018ffaf73ff69a6c5187d76b1af52d89",
"parentId": "bab076869db66a29",
"id": "c2672657d8240228",
"name": "defaultazurecredential.get_token",
"timestamp": 1563911360274018,
"duration": 11999,
"localEndpoint": {
"serviceName": "suyog-azure-core-v0.01-opencensus",
"port": 9411
}
},
{
"traceId": "018ffaf73ff69a6c5187d76b1af52d89",
"parentId": "37514dc26cea2fe7",
"id": "bab076869db66a29",
"name": "keyclient.get_key",
"timestamp": 1563911360274018,
"duration": 161035,
"localEndpoint": {
"serviceName": "suyog-azure-core-v0.01-opencensus",
"port": 9411
}
},
{
"traceId": "018ffaf73ff69a6c5187d76b1af52d89",
"parentId": "bab076869db66a29",
"id": "1beade5189a4f118",
"kind": "CLIENT",
"name": "/keys/key-name/",
"timestamp": 1563911360291017,
"duration": 139033,
"localEndpoint": {
"serviceName": "suyog-azure-core-v0.01-opencensus",
"port": 9411
},
"tags": {
"component": "http",
"http.method": "GET",
"http.status_code": "200",
"http.url": "https://susoti-vault.vault.azure.net/keys/key-name/?api-version=7.0",
"http.user_agent": "python/3.7.3 (Windows-10-10.0.18362-SP0) azure-core/1.0.0b2 azsdk-python-azure-keyvault/7.0",
"x-ms-client-request-id": "f665efdc-ad82-11e9-b89c-b831b59ea690",
"x-ms-request-id": "72639b8d-46c1-433d-8fb0-cf160052a87b"
}
},
{
"traceId": "018ffaf73ff69a6c5187d76b1af52d89",
"parentId": "37514dc26cea2fe7",
"id": "6da3cb404385690a",
"name": "do something else",
"timestamp": 1563911360441019,
"duration": 100405,
"localEndpoint": {
"serviceName": "suyog-azure-core-v0.01-opencensus",
"port": 9411
}
},
{
"traceId": "018ffaf73ff69a6c5187d76b1af52d89",
"parentId": "fdb2a0aaaf2cbab1",
"id": "c10090afac4f0d90",
"name": "clientsecretcredential.get_token",
"timestamp": 1563911360555385,
"localEndpoint": {
"serviceName": "suyog-azure-core-v0.01-opencensus",
"port": 9411
}
},
{
"traceId": "018ffaf73ff69a6c5187d76b1af52d89",
"parentId": "f9c5e4deab50962a",
"id": "fdb2a0aaaf2cbab1",
"name": "environmentcredential.get_token",
"timestamp": 1563911360555385,
"duration": 6046,
"localEndpoint": {
"serviceName": "suyog-azure-core-v0.01-opencensus",
"port": 9411
}
},
{
"traceId": "018ffaf73ff69a6c5187d76b1af52d89",
"parentId": "bcc81c83794076fa",
"id": "f9c5e4deab50962a",
"name": "defaultazurecredential.get_token",
"timestamp": 1563911360555385,
"duration": 12014,
"localEndpoint": {
"serviceName": "suyog-azure-core-v0.01-opencensus",
"port": 9411
}
},
{
"traceId": "018ffaf73ff69a6c5187d76b1af52d89",
"parentId": "bcc81c83794076fa",
"id": "f9455d0568c328d8",
"kind": "CLIENT",
"name": "/keys",
"timestamp": 1563911360572384,
"duration": 303042,
"localEndpoint": {
"serviceName": "suyog-azure-core-v0.01-opencensus",
"port": 9411
},
"tags": {
"component": "http",
"http.method": "GET",
"http.status_code": "200",
"http.url": "https://susoti-vault.vault.azure.net:443/keys?api-version=7.0&$skiptoken=eyJOZXh0TWFya2VyIjoiMiE3MiFNREF3TURFd0lXdGxlUzlMUlZrdE1",
"http.user_agent": "python/3.7.3 (Windows-10-10.0.18362-SP0) azure-core/1.0.0b2 azsdk-python-azure-keyvault/7.0",
"x-ms-client-request-id": "f690dec0-ad82-11e9-a40e-b831b59ea690",
"x-ms-request-id": "69a1fc8c-883a-4e09-8716-be7855bbda27"
}
},
{
"traceId": "018ffaf73ff69a6c5187d76b1af52d89",
"parentId": "8ed2b177f055215b",
"id": "d2864f279be3eb85",
"name": "clientsecretcredential.get_token",
"timestamp": 1563911360911405,
"duration": 1025,
"localEndpoint": {
"serviceName": "suyog-azure-core-v0.01-opencensus",
"port": 9411
}
},
{
"traceId": "018ffaf73ff69a6c5187d76b1af52d89",
"parentId": "4ec19583057ba7e1",
"id": "8ed2b177f055215b",
"name": "environmentcredential.get_token",
"timestamp": 1563911360911405,
"duration": 5985,
"localEndpoint": {
"serviceName": "suyog-azure-core-v0.01-opencensus",
"port": 9411
}
},
{
"traceId": "018ffaf73ff69a6c5187d76b1af52d89",
"parentId": "bcc81c83794076fa",
"id": "4ec19583057ba7e1",
"name": "defaultazurecredential.get_token",
"timestamp": 1563911360911405,
"duration": 9983,
"localEndpoint": {
"serviceName": "suyog-azure-core-v0.01-opencensus",
"port": 9411
}
},
{
"traceId": "018ffaf73ff69a6c5187d76b1af52d89",
"parentId": "bcc81c83794076fa",
"id": "5d0e8548546462a2",
"kind": "CLIENT",
"name": "/keys",
"timestamp": 1563911360924387,
"duration": 76999,
"localEndpoint": {
"serviceName": "suyog-azure-core-v0.01-opencensus",
"port": 9411
},
"tags": {
"component": "http",
"http.method": "GET",
"http.status_code": "200",
"http.url": "https://susoti-vault.vault.azure.net:443/keys?api-version=7.0&$skiptoken=eyJOZXh0TWFya2VyIjoiMiE3NiFNREF3TURFeUlXdGxlUzlMUlZrdFR",
"http.user_agent": "python/3.7.3 (Windows-10-10.0.18362-SP0) azure-core/1.0.0b2 azsdk-python-azure-keyvault/7.0",
"x-ms-client-request-id": "f6c731c6-ad82-11e9-b18e-b831b59ea690",
"x-ms-request-id": "ba83748d-aa18-4227-8820-c296ef72811e"
}
},
{
"traceId": "018ffaf73ff69a6c5187d76b1af52d89",
"parentId": "37514dc26cea2fe7",
"id": "bcc81c83794076fa",
"name": "rest of the pages",
"timestamp": 1563911360545385,
"duration": 462020,
"localEndpoint": {
"serviceName": "suyog-azure-core-v0.01-opencensus",
"port": 9411
}
},
{
"traceId": "018ffaf73ff69a6c5187d76b1af52d89",
"id": "37514dc26cea2fe7",
"name": "parent",
"timestamp": 1563911358481070,
"duration": 2530349,
"localEndpoint": {
"serviceName": "suyog-azure-core-v0.01-opencensus",
"port": 9411
}
}
]
import os
import time
from azure.keyvault.keys import KeyClient
from azure.identity import DefaultAzureCredential
from opencensus.ext.zipkin.trace_exporter import ZipkinExporter
from opencensus.trace.samplers import AlwaysOnSampler
from opencensus.trace import tracer as tracer_module
# MAKE SURE TO SET THE APPROPRIATE CREDNTIAL
azure_credential = DefaultAzureCredential()
zipExportInst = ZipkinExporter(service_name="suyog-azure-core-v0.01-opencensus", host_name="localhost", port=9411)
tracer = tracer_module.Tracer(sampler=AlwaysOnSampler(), exporter=zipExportInst)
with tracer.span("parent") as parent:
client = KeyClient("https://susoti-vault.vault.azure.net/", azure_credential)
for index in range(2):
client.create_key("key-{}".format(index), "RSA")
keys = client.list_keys(max_page_size=10)
with tracer.span("first page"):
for key in keys:
print("{} -> {}".format(key.name, key.id))
break
key = client.get_key("key-name")
print("{} -> {}".format(key.name, key.id))
with tracer.span("do something else"):
time.sleep(0.1)
with tracer.span("Rest of the pages") as chld:
for key in keys:
print("{} -> {}".format(key.name, key.id))
tracer.finish()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment