Skip to content
This repository was archived by the owner on Aug 13, 2025. It is now read-only.

Commit dba8928

Browse files
feat: support classic ingest keys (#180)
## Which problem is this PR solving? We've released Ingest Keys, but need to update the key detection logic to allow Ingest Keys to be used to send data to Classic environments. ## Short description of the changes - updates the Classic API Key detection logic to understand the shape of a Classic Ingest Key - updates tests with a more comprehensive list of cases ## How to verify that this has the expected result It should be possible to use [an ingest key](https://docs.honeycomb.io/working-with-your-data/settings/api-keys/#ingest-keys-1) pointed to a classic environment after this change. Please note that the ability to create ingest keys in classic environments isn't yet publicly available (since we need to update this library and others to understand classic ingest keys).
1 parent 6a31d89 commit dba8928

File tree

3 files changed

+39
-6
lines changed

3 files changed

+39
-6
lines changed

src/honeycomb/opentelemetry/options.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import logging
22
import os
3+
import re
34
from opentelemetry.sdk.environment_variables import (
45
OTEL_EXPORTER_OTLP_ENDPOINT,
56
OTEL_EXPORTER_OTLP_INSECURE,
@@ -92,13 +93,21 @@
9293
def is_classic(apikey: str) -> bool:
9394
"""
9495
Determines whether the passed in API key is a classic API key or not.
95-
Modern API keys have 22 or 23 characters.
96-
Classic API keys have 32 characters.
96+
v1 Configuration API keys have 22 or 23 characters.
97+
v1 Classic Configuration API keys have 32 characters.
98+
v2 Ingest keys have 64 characters and a prefix of hcxik.
99+
v2 Classic Ingest keys have 64 characters and a prefix of hcxic.
97100
98101
Returns:
99102
bool: true if the api key is a classic key, false if not
100103
"""
101-
return apikey and len(apikey) == 32
104+
if not apikey:
105+
return False
106+
if re.match(r'^[a-f0-9]{32}$', apikey):
107+
return True
108+
if re.match(r'^hc[a-z]ic_[a-z0-9]{58}$', apikey):
109+
return True
110+
return False
102111

103112

104113
def parse_bool(environment_variable: str,

tests/test_options.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@
77
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT,
88
OTEL_SERVICE_NAME,
99
)
10-
from tests.utils import APIKEY
10+
from tests.utils import (
11+
APIKEY,
12+
CLASSIC_APIKEY,
13+
INGEST_APIKEY,
14+
CLASSIC_INGEST_APIKEY,
15+
)
1116
from honeycomb.opentelemetry.options import (
1217
DEBUG,
1318
DEFAULT_API_ENDPOINT,
@@ -21,6 +26,7 @@
2126
HONEYCOMB_METRICS_APIKEY,
2227
HONEYCOMB_METRICS_DATASET,
2328
HONEYCOMB_TRACES_APIKEY,
29+
is_classic,
2430
SAMPLE_RATE
2531
)
2632

@@ -575,3 +581,18 @@ def test_debug_sets_log_level_to_debug():
575581
def test_debug_with_custom_log_level_sets_log_level_to_debug():
576582
options = HoneycombOptions(debug=True, log_level="INFO")
577583
assert options.log_level == "DEBUG"
584+
585+
def test_empty_key():
586+
assert is_classic("") == False
587+
588+
def test_configuration_key():
589+
assert is_classic(APIKEY) == False
590+
591+
def test_ingest_key():
592+
assert is_classic(INGEST_APIKEY) == False
593+
594+
def test_classic_configuration_key():
595+
assert is_classic(CLASSIC_APIKEY) == True
596+
597+
def test_classic_ingest_key():
598+
assert is_classic(CLASSIC_INGEST_APIKEY) == True

tests/utils.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
# classic keys are 32 chars long
2-
CLASSIC_APIKEY = "this is a string that is 32 char"
2+
CLASSIC_APIKEY = "c1a551c1111111111111111111111111"
33
# non-classic keys are 22 chars log
4-
APIKEY = "an api key for 22 char"
4+
APIKEY = "shinynewenvironmentkey"
5+
# v2 key format
6+
CLASSIC_INGEST_APIKEY="hcxic_1234567890123456789012345678901234567890123456789012345678"
7+
INGEST_APIKEY="hcxik_1234567890123456789012345678901234567890123456789012345678"

0 commit comments

Comments
 (0)