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 Classic Ingest Key support #245

Merged
merged 3 commits into from
Mar 4, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions otlp/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ const (
const fieldSizeMax = math.MaxUint16

var (
legacyApiKeyPattern = regexp.MustCompile("^[0-9a-f]{32}$")
legacyApiKeyPattern = regexp.MustCompile("^[0-9a-f]*$")
classicIngestKeyPattern = regexp.MustCompile("^hc[a-z]ic_[0-9a-z]*$")
// Incoming OpenTelemetry HTTP Content-Types (e.g. "application/protobuf") we support
supportedContentTypes = []string{
"application/protobuf",
Expand Down Expand Up @@ -87,6 +88,18 @@ func IsContentTypeSupported(contentType string) bool {
return false
}

// IsLegacyApiKey checks if the given API key is a legacy (classic) API key.
func IsLegacyApiKey(key string) bool {
if len(key) == 0 {
return true
} else if len(key) == 32 {
return legacyApiKeyPattern.MatchString(key)
} else if len(key) == 64 {
return classicIngestKeyPattern.MatchString(key)
}
return false
}

// List of HTTP Content Encodings supported for OTLP ingest.
func GetSupportedContentEncodings() []string {
return supportedContentEncodings
Expand Down Expand Up @@ -127,7 +140,7 @@ type RequestInfo struct {
}

func (ri RequestInfo) hasLegacyKey() bool {
return legacyApiKeyPattern.MatchString(ri.ApiKey)
return IsLegacyApiKey(ri.ApiKey)
}

// ValidateTracesHeaders validates required headers/metadata for a trace OTLP request
Expand Down
Loading