Object.defineProperty(exports, '__esModule', { value: true });

const instrumentationKafkajs = require('@opentelemetry/instrumentation-kafkajs');
const core = require('@sentry/core');
const instrument = require('../../otel/instrument.js');
const addOriginToSpan = require('../../utils/addOriginToSpan.js');

const INTEGRATION_NAME = 'Kafka';

const instrumentKafka = instrument.generateInstrumentOnce(
  INTEGRATION_NAME,
  () =>
    new instrumentationKafkajs.KafkaJsInstrumentation({
      consumerHook(span) {
        addOriginToSpan.addOriginToSpan(span, 'auto.kafkajs.otel.consumer');
      },
      producerHook(span) {
        addOriginToSpan.addOriginToSpan(span, 'auto.kafkajs.otel.producer');
      },
    }),
);

const _kafkaIntegration = (() => {
  return {
    name: INTEGRATION_NAME,
    setupOnce() {
      instrumentKafka();
    },
  };
}) ;

/**
 * KafkaJs integration
 *
 * Capture tracing data for KafkaJs.
 */
const kafkaIntegration = core.defineIntegration(_kafkaIntegration);

exports.instrumentKafka = instrumentKafka;
exports.kafkaIntegration = kafkaIntegration;
