Skip to content
This repository has been archived by the owner on Dec 20, 2021. It is now read-only.

HoneycombConsoleSpanExporter doesn't seem to work with agentless publisher #39

Closed
ajbouh opened this issue Aug 16, 2021 · 2 comments
Closed

Comments

@ajbouh
Copy link

ajbouh commented Aug 16, 2021

Is there a reason the HoneycombConsoleSpanExporter and FileTransmission are implemented so differently?

Compare:

def export(self, spans):
for d in _translate_to_hny(spans):
del d["start_time"] # trust API log timestamp?
self.out.write(self.formatter(d))
self.out.flush()
return SpanExportResult.SUCCESS

with the corresponding implementation in libhoney-py:

https://github.com/honeycombio/libhoney-py/blob/6cc1e205184ab4a0117e00864fc982656f5cbacc/libhoney/transmission.py#L464-L482

@ajbouh
Copy link
Author

ajbouh commented Aug 18, 2021

The code I'm using looks a bit like this:

from opentelemetry import trace
from opentelemetry.sdk.trace.export import SpanExporter, SpanExportResult, SimpleSpanProcessor
from opentelemetry.ext.honeycomb import _translate_to_hny
from libhoney.version import VERSION
from libhoney.internal import json_default_handler
import json

# We use our own implementation, since the main one deletes 
class HoneycombConsoleSpanExporter(SpanExporter):
  """Honeycomb console span exporter for the Honeycomb AWS Lambda Instrumentation.
  """
  def __init__(
    self,
    service_name=None,
    out=sys.stdout,
    dataset=None,
    user_agent_addition='',
    sample_rate=1,
  ):
    self.out = out
    self.service_name = service_name
    self.sample_rate = sample_rate
    self.dataset = dataset
    self.user_agent = "libhoney-py/" + VERSION
    if user_agent_addition:
        self.user_agent += " " + user_agent_addition

  def export(self, spans):
    dataset = self.dataset
    user_agent = self.user_agent
    out = self.out
    sample_rate = self.sample_rate

    for d in _translate_to_hny(spans):
      start_time = d["start_time"]
      del d["start_time"]

      event_time = start_time.isoformat()
      if start_time.tzinfo is None:
        event_time += "Z"

      # we add dataset and user_agent to the payload
      # if processed by another honeycomb agent (i.e. agentless integrations
      # for AWS), this data will get used to route the event to the right
      # location with appropriate metadata
      payload = {
        "time": event_time,
        "samplerate": sample_rate,
        "dataset": dataset,
        "user_agent": user_agent,
        "data": d,
      }
      out.write(json.dumps(payload, default=json_default_handler) + os.linesep)
    out.flush()
    return SpanExportResult.SUCCESS

import os
import sys
dataset = os.environ['HONEYCOMB_DATASET']
service_name = os.environ['HONEYCOMB_SERVICE_NAME']

exporter = HoneycombConsoleSpanExporter(
  service_name=service_name,
  out=sys.stdout,
  dataset=dataset,
)

trace.get_tracer_provider().add_span_processor(SimpleSpanProcessor(exporter))

@JamieDanielson
Copy link
Contributor

Hi @ajbouh,

As mentioned in issue #36, this project is being sunset and so unfortunately we do not have plans to make any further changes to this repo. We will continue to monitor discussion on that sunset issue in the meantime.

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

No branches or pull requests

2 participants