Skip to content

Commit

Permalink
Object creation seems to work even with recursive samplers
Browse files Browse the repository at this point in the history
  • Loading branch information
ocelotl committed Dec 5, 2023
1 parent 820fc36 commit facdba4
Show file tree
Hide file tree
Showing 3 changed files with 163 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,9 @@ def create_object(
def create_object(
configuration: dict,
processed_schema: dict,
path_function: dict
path_function: dict,
original_processed_schema: dict,
original_path_function: dict,
) -> object:

positional_arguments = []
Expand All @@ -579,12 +581,42 @@ def create_object(

if isinstance(configuration_value, dict):

if processed_schema["recursive_path"]:
set_trace()

new_processed_schema = original_processed_schema
new_path_function = original_path_function

for path in processed_schema["recursive_path"]:
new_processed_schema = (
new_processed_schema[path]["children"]
)
new_path_function = (
new_path_function[path]["children"]
)

new_processed_schema = (
new_processed_schema[configuration_key]
)
new_path_function = (
new_path_function[configuration_key]
)
else:
new_processed_schema = (
processed_schema["children"][configuration_key]
)
new_path_function = (
path_function["children"][configuration_key]
)

object_ = create_object(
configuration_value,
processed_schema["children"][configuration_key],
new_processed_schema,
# If recursive_path don't pass this dictionary below but
# the one pointed by the recursive_path
path_function["children"][configuration_key]
new_path_function,
original_processed_schema,
original_path_function,
)

elif isinstance(configuration_value, list):
Expand All @@ -597,7 +629,9 @@ def create_object(
create_object(
element,
processed_schema["children"][configuration_key],
path_function["children"][configuration_key]
path_function["children"][configuration_key],
original_processed_schema,
original_path_function,
)
)

Expand All @@ -620,5 +654,7 @@ def create_object(
return create_object(
configuration[object_name],
processed_schema[object_name],
path_function[object_name]
path_function[object_name],
processed_schema,
path_function,
)
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,22 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from opentelemetry.sdk.resources import Resource
from opentelemetry.sdk.trace import (
TracerProvider, SynchronousMultiSpanProcessor, SpanLimits
)
from opentelemetry.sdk.trace.export import (
BatchSpanProcessor, ConsoleSpanExporter, SimpleSpanProcessor
)
from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import (
OTLPSpanExporter as GRPCOTLPSpanExporter
)
from opentelemetry.exporter.otlp.proto.http.trace_exporter import (
OTLPSpanExporter as HTTPOTLPSpanExporter
)
from opentelemetry.exporter.zipkin.proto.http import ZipkinExporter
from urllib.parse import urlparse
from ipdb import set_trace

_resource = None

Expand Down Expand Up @@ -310,15 +326,33 @@ def tracer_provider(
processors: list = None,
sampler: object = None
):
pass
# FIXME how to define shutdown_on_exit?
# FIXME how to define id_generator?
# FIXME how to define if the span processors should be synchronous or not?

set_trace()

synchronous_multi_span_processor = SynchronousMultiSpanProcessor()

if processors is not None:
for processor in processors:
synchronous_multi_span_processor.add_span_processor(processor)

return TracerProvider(
sampler=sampler,
resource=_resource,
active_span_processor=synchronous_multi_span_processor,
span_limits=limits
)


def tracer_provider_processors(
batch: object = None,
simple: object = None,
**kwargs
):
pass
set_trace()
return batch or simple


def tracer_provider_processors_batch(
Expand All @@ -328,7 +362,14 @@ def tracer_provider_processors_batch(
max_queue_size: int = None,
schedule_delay: int = None
):
pass
set_trace()
return BatchSpanProcessor(
exporter,
max_queue_size=max_queue_size,
schedule_delay_millis=schedule_delay,
max_export_batch_size=max_export_batch_size,
export_timeout_millis=export_timeout
)


def tracer_provider_processors_batch_exporter(
Expand All @@ -337,7 +378,8 @@ def tracer_provider_processors_batch_exporter(
zipkin: object = None,
**kwargs
):
pass
set_trace()
return console or otlp or zipkin


def tracer_provider_processors_batch_exporter_otlp(
Expand All @@ -350,30 +392,52 @@ def tracer_provider_processors_batch_exporter_otlp(
headers: object = None,
timeout: int = None
):
pass
set_trace()
protocol = urlparse(protocol).scheme

if protocol.startswith("http"):
exporter_class = HTTPOTLPSpanExporter

else:
exporter_class = GRPCOTLPSpanExporter

return exporter_class(
endpoint=endpoint,
# insecure=None,
# FIXME somehow create credentials here
# from grpc.credentials import create_credentials
# credentials=create_credentials()
headers=headers,
timeout=timeout,
# compression=compression
)


def tracer_provider_processors_batch_exporter_otlp_headers(
**kwargs
):
pass
set_trace()
return kwargs


def tracer_provider_processors_batch_exporter_console():
return ConsoleSpanExporter
pass


def tracer_provider_processors_batch_exporter_zipkin(
endpoint: str,
timeout: int = None
):
pass
set_trace()
return ZipkinExporter(endpoint, timeout=timeout)


def tracer_provider_processors_simple(
exporter: object
):
pass
set_trace()
return SimpleSpanProcessor(exporter)


def tracer_provider_processors_simple_exporter(
Expand All @@ -382,7 +446,8 @@ def tracer_provider_processors_simple_exporter(
zipkin: object = None,
**kwargs
):
pass
set_trace()
return console or otlp or zipkin


def tracer_provider_processors_simple_exporter_otlp(
Expand All @@ -395,24 +460,45 @@ def tracer_provider_processors_simple_exporter_otlp(
headers: object = None,
timeout: int = None
):
pass
set_trace()
protocol = urlparse(protocol).scheme

if protocol.startswith("http"):
exporter_class = HTTPOTLPSpanExporter

else:
exporter_class = GRPCOTLPSpanExporter

return exporter_class(
endpoint=endpoint,
# insecure=None,
# FIXME somehow create credentials here
# from grpc.credentials import create_credentials
# credentials=create_credentials()
headers=headers,
timeout=timeout,
# compression=compression
)


def tracer_provider_processors_simple_exporter_otlp_headers(
**kwargs
):
pass
set_trace()
return kwargs


def tracer_provider_processors_simple_exporter_console():
pass
set_trace()
return ConsoleSpanExporter()


def tracer_provider_processors_simple_exporter_zipkin(
endpoint: str,
timeout: int = None
):
pass
set_trace()
return ZipkinExporter(endpoint, timeout=timeout)


def tracer_provider_limits(
Expand All @@ -423,7 +509,15 @@ def tracer_provider_limits(
link_attribute_count_limit: int = None,
link_count_limit: int = None
):
pass
set_trace()
return SpanLimits(
max_span_attributes=attribute_count_limit,
max_span_attribute_length=attribute_value_length_limit,
max_event_attributes=event_count_limit,
max_events=event_count_limit,
max_link_attributes=link_attribute_count_limit,
max_links=link_count_limit,
)


def tracer_provider_sampler(
Expand All @@ -434,14 +528,17 @@ def tracer_provider_sampler(
trace_id_ratio_based: object = None,
**kwargs
):
set_trace()
pass


def tracer_provider_sampler_always_off():
set_trace()
pass


def tracer_provider_sampler_always_on():
set_trace()
pass


Expand All @@ -450,6 +547,7 @@ def tracer_provider_sampler_jaeger_remote(
initial_sampler: object = None,
interval: int = None
):
set_trace()
pass


Expand All @@ -461,6 +559,7 @@ def tracer_provider_sampler_jaeger_remote_initial_sampler(
trace_id_ratio_based: object = None,
**kwargs
):
set_trace()
pass


Expand All @@ -471,6 +570,7 @@ def tracer_provider_sampler_parent_based(
remote_parent_sampled: object = None,
root: object = None
):
set_trace()
pass


Expand All @@ -482,6 +582,7 @@ def tracer_provider_sampler_parent_based_root(
trace_id_ratio_based: object = None,
**kwargs
):
set_trace()
pass


Expand All @@ -493,6 +594,7 @@ def tracer_provider_sampler_parent_based_remote_parent_sampled(
trace_id_ratio_based: object = None,
**kwargs
):
set_trace()
pass


Expand All @@ -504,6 +606,7 @@ def tracer_provider_sampler_parent_based_remote_parent_not_sampled(
trace_id_ratio_based: object = None,
**kwargs
):
set_trace()
pass


Expand All @@ -515,6 +618,7 @@ def tracer_provider_sampler_parent_based_local_parent_sampled(
trace_id_ratio_based: object = None,
**kwargs
):
set_trace()
pass


Expand All @@ -526,12 +630,14 @@ def tracer_provider_sampler_parent_based_local_parent_not_sampled(
trace_id_ratio_based: object = None,
**kwargs
):
set_trace()
pass


def tracer_provider_sampler_trace_id_ratio_based(
ratio: float = None
):
set_trace()
pass


Expand Down
Loading

0 comments on commit facdba4

Please sign in to comment.