Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat]: Add OTLP HTTP/JSON traces exporter #3681

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

MikeGoldsmith
Copy link
Member

Description

Adds a OTLP HTTP/JSON exporter. Currently only exports trace data, but can be expanded to add metrics and logs too.

Fixes #1003

NOTE: I've created as a draft to gather feedback and will add more tests. Also needs lint rules applied too.

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • Add simple Unit Test to verify JSON output, want to add more

Does This PR Require a Contrib Repo Change?

  • Yes. - Link to PR:
  • No.

Checklist:

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

data = serialized_data
if self._compression == Compression.Gzip:
gzip_data = BytesIO()
with gzip.GzipFile(fileobj=gzip_data, mode="w") as gzip_stream:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

encoding="utf-8"

gzip_stream.write(serialized_data)
data = gzip_data.getvalue()
elif self._compression == Compression.Deflate:
data = zlib.compress(bytes(serialized_data))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
data = zlib.compress(bytes(serialized_data))
data = zlib.compress(serialized_data.encode())
>>> bytes("foo")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: string argument without an encoding

DEFAULT_TIMEOUT = 10 # in seconds
REQUESTS_SUCCESS_STATUS_CODES = (200, 202)

logger = logging.getLogger(__name__)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This module has both of logger and _logger.

# Second loop encodes the data into JSON format.
#

sdk_resource_spans = defaultdict(lambda: defaultdict(list))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function should use protobuf json serializer.

from opentelemetry.exporter.otlp.proto.common.trace_encoder import (
    encode_spans,
)
from google.protobuf import json_format

message = encode_spans(sdk_spans)
return json_format.MessageToJson(message, indent=None)

@methane
Copy link
Contributor

methane commented Feb 22, 2024

exporter-otlp-json can be just copy of exporter-otlp-proto-http and just replace these lines:

into json_format.MessageToJson(encode_xxx(...), indent=None).

@methane
Copy link
Contributor

methane commented Feb 22, 2024

Or can we just add json option to otlp-proto-http exporter? They are very close.
How other languages implement them?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support JSON over HTTP in OTLP exporter
2 participants