|
1 | 1 | # (c) Copyright IBM Corp. 2021
|
2 | 2 | # (c) Copyright Instana Inc. 2020
|
3 | 3 |
|
| 4 | +import os |
4 | 5 | from typing import Generator
|
5 | 6 |
|
6 | 7 | import boto3
|
7 | 8 | import pytest
|
8 | 9 | from moto import mock_aws
|
9 | 10 |
|
| 11 | +from instana.options import StandardOptions |
10 | 12 | from instana.singletons import agent, tracer
|
11 | 13 | from tests.helpers import get_first_span_by_filter
|
12 | 14 |
|
@@ -67,6 +69,55 @@ def test_dynamodb_create_table(self) -> None:
|
67 | 69 | assert dynamodb_span.data["dynamodb"]["region"] == "us-west-2"
|
68 | 70 | assert dynamodb_span.data["dynamodb"]["table"] == "dynamodb-table"
|
69 | 71 |
|
| 72 | + def test_ignore_dynamodb(self) -> None: |
| 73 | + os.environ["INSTANA_IGNORE_ENDPOINTS"] = "dynamodb" |
| 74 | + agent.options = StandardOptions() |
| 75 | + |
| 76 | + with tracer.start_as_current_span("test"): |
| 77 | + self.dynamodb.create_table( |
| 78 | + TableName="dynamodb-table", |
| 79 | + KeySchema=[{"AttributeName": "id", "KeyType": "HASH"}], |
| 80 | + AttributeDefinitions=[{"AttributeName": "id", "AttributeType": "S"}], |
| 81 | + ProvisionedThroughput={"ReadCapacityUnits": 1, "WriteCapacityUnits": 1}, |
| 82 | + ) |
| 83 | + |
| 84 | + spans = self.recorder.queued_spans() |
| 85 | + assert len(spans) == 2 |
| 86 | + |
| 87 | + filter = lambda span: span.n == "dynamodb" # noqa: E731 |
| 88 | + dynamodb_span = get_first_span_by_filter(spans, filter) |
| 89 | + assert dynamodb_span |
| 90 | + |
| 91 | + filtered_spans = agent.filter_spans(spans) |
| 92 | + assert len(filtered_spans) == 1 |
| 93 | + |
| 94 | + assert dynamodb_span not in filtered_spans |
| 95 | + |
| 96 | + def test_ignore_create_table(self) -> None: |
| 97 | + os.environ["INSTANA_IGNORE_ENDPOINTS"] = "dynamodb.createtable" |
| 98 | + agent.options = StandardOptions() |
| 99 | + |
| 100 | + with tracer.start_as_current_span("test"): |
| 101 | + self.dynamodb.create_table( |
| 102 | + TableName="dynamodb-table", |
| 103 | + KeySchema=[{"AttributeName": "id", "KeyType": "HASH"}], |
| 104 | + AttributeDefinitions=[{"AttributeName": "id", "AttributeType": "S"}], |
| 105 | + ProvisionedThroughput={"ReadCapacityUnits": 1, "WriteCapacityUnits": 1}, |
| 106 | + ) |
| 107 | + self.dynamodb.list_tables() |
| 108 | + |
| 109 | + spans = self.recorder.queued_spans() |
| 110 | + assert len(spans) == 3 |
| 111 | + |
| 112 | + filtered_spans = agent.filter_spans(spans) |
| 113 | + assert len(filtered_spans) == 2 |
| 114 | + |
| 115 | + filter = lambda span: span.n == "dynamodb" # noqa: E731 |
| 116 | + dynamodb_span = get_first_span_by_filter(filtered_spans, filter) |
| 117 | + |
| 118 | + assert dynamodb_span.n == "dynamodb" |
| 119 | + assert dynamodb_span.data["dynamodb"]["op"] == "ListTables" |
| 120 | + |
70 | 121 | def test_dynamodb_create_table_as_root_exit_span(self) -> None:
|
71 | 122 | agent.options.allow_exit_as_root = True
|
72 | 123 | self.dynamodb.create_table(
|
|
0 commit comments