Skip to content
This repository was archived by the owner on Sep 17, 2025. It is now read-only.

Commit 9d6a607

Browse files
authored
Add links for trace exporter envelopes (#936)
1 parent 6754bf4 commit 9d6a607

File tree

4 files changed

+26
-31
lines changed

4 files changed

+26
-31
lines changed

contrib/opencensus-ext-azure/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
([#930](https://github.com/census-instrumentation/opencensus-python/pull/930))
77
- Attach rate metrics for VM
88
([#935](https://github.com/census-instrumentation/opencensus-python/pull/935))
9+
- Add links in properties for trace exporter envelopes
10+
([#936](https://github.com/census-instrumentation/opencensus-python/pull/936))
911

1012
## 1.0.4
1113
Released 2020-06-29

contrib/opencensus-ext-azure/examples/traces/config.py

Lines changed: 0 additions & 29 deletions
This file was deleted.

contrib/opencensus-ext-azure/opencensus/ext/azure/trace_exporter/__init__.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import json
1516
import logging
1617

1718
from opencensus.common.schedule import QueueExitEvent
@@ -146,7 +147,13 @@ def span_data_to_envelope(self, sd):
146147
else:
147148
data.type = 'INPROC'
148149
data.success = True
149-
# TODO: links, tracestate, tags
150+
if sd.links:
151+
links = []
152+
for link in sd.links:
153+
links.append(
154+
{"operation_Id": link.trace_id, "id": link.span_id})
155+
data.properties["_MS.links"] = json.dumps(links)
156+
# TODO: tracestate, tags
150157
for key in sd.attributes:
151158
# This removes redundant data from ApplicationInsights
152159
if key.startswith('http.'):

contrib/opencensus-ext-azure/tests/test_azure_trace_exporter.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import json
1516
import os
1617
import shutil
1718
import unittest
1819

1920
import mock
2021

2122
from opencensus.ext.azure import trace_exporter
23+
from opencensus.trace.link import Link
2224

2325
TEST_FOLDER = os.path.abspath('.test.exporter')
2426

@@ -141,7 +143,9 @@ def test_span_data_to_envelope(self):
141143
start_time='2010-10-24T07:28:38.123456Z',
142144
end_time='2010-10-24T07:28:38.234567Z',
143145
stack_trace=None,
144-
links=None,
146+
links=[
147+
Link('6e0c63257de34c90bf9efcd03927272e', '6e0c63257de34c91')
148+
],
145149
status=Status(0),
146150
annotations=None,
147151
message_events=None,
@@ -188,6 +192,17 @@ def test_span_data_to_envelope(self):
188192
self.assertEqual(
189193
envelope.data.baseType,
190194
'RemoteDependencyData')
195+
json_dict = json.loads(
196+
envelope.data.baseData.properties["_MS.links"]
197+
)[0]
198+
self.assertEqual(
199+
json_dict["id"],
200+
"6e0c63257de34c91",
201+
)
202+
self.assertEqual(
203+
json_dict["operation_Id"],
204+
"6e0c63257de34c90bf9efcd03927272e",
205+
)
191206

192207
# SpanKind.CLIENT unknown type
193208
envelope = exporter.span_data_to_envelope(SpanData(

0 commit comments

Comments
 (0)