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

Closed

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?

@ocelotl
Copy link
Contributor

ocelotl commented Jun 28, 2024

@MikeGoldsmith are you still working on this PR?

@MikeGoldsmith
Copy link
Member Author

Hi @ocelotl - I had the intention of keeping this going but have struggled to get back to it.

It's probably best to close this PR and unassign me from the issue. If I find I get more time and it's still available, I'll put my hand up again.

Thanks

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
3 participants