All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.opentelemetry.exporter.zipkin.BytesEncoderAdapter Maven / Gradle / Ivy

There is a newer version: 1.44.1
Show newest version
/*
 * Copyright The OpenTelemetry Authors
 * SPDX-License-Identifier: Apache-2.0
 */

package io.opentelemetry.exporter.zipkin;

import zipkin2.Span;
import zipkin2.reporter.BytesEncoder;
import zipkin2.reporter.Encoding;

/**
 * This supports the deprecated method {@link
 * ZipkinSpanExporterBuilder#setEncoder(zipkin2.codec.BytesEncoder)}.
 */
final class BytesEncoderAdapter implements BytesEncoder {
  private final zipkin2.codec.BytesEncoder delegate;
  private final Encoding encoding;

  @SuppressWarnings("deprecation") // we have to use the deprecated thrift encoding to return it
  BytesEncoderAdapter(zipkin2.codec.BytesEncoder delegate) {
    this.delegate = delegate;
    switch (delegate.encoding()) {
      case JSON:
        this.encoding = Encoding.JSON;
        break;
      case PROTO3:
        this.encoding = Encoding.PROTO3;
        break;
      case THRIFT:
        this.encoding = Encoding.THRIFT;
        break;
      default:
        // Only possible if zipkin2 adds an encoding besides above, which is very unlikely.
        throw new UnsupportedOperationException("unsupported encoding " + delegate.encoding());
    }
  }

  @Override
  public Encoding encoding() {
    return encoding;
  }

  @Override
  public int sizeInBytes(Span span) {
    return delegate.sizeInBytes(span);
  }

  @Override
  public byte[] encode(Span span) {
    return delegate.encode(span);
  }

  @Override
  public String toString() {
    return delegate.toString();
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy