Skip to content

Azureblob exporter draft PR #35717

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

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
27 changes: 27 additions & 0 deletions .chloggen/azureblob-exporter-skeleton.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: new_component

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: azureblobexporter

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Add new exporter for sending telemetry to Azure Storage Blob

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: []

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [user]
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/bug_report.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ body:
- exporter/awskinesis
- exporter/awss3
- exporter/awsxray
- exporter/azureblob
- exporter/azuredataexplorer
- exporter/azuremonitor
- exporter/carbon
Expand Down
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/feature_request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ body:
- exporter/awskinesis
- exporter/awss3
- exporter/awsxray
- exporter/azureblob
- exporter/azuredataexplorer
- exporter/azuremonitor
- exporter/carbon
Expand Down
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/other.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ body:
- exporter/awskinesis
- exporter/awss3
- exporter/awsxray
- exporter/azureblob
- exporter/azuredataexplorer
- exporter/azuremonitor
- exporter/carbon
Expand Down
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/unmaintained.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ body:
- exporter/awskinesis
- exporter/awss3
- exporter/awsxray
- exporter/azureblob
- exporter/azuredataexplorer
- exporter/azuremonitor
- exporter/carbon
Expand Down
1 change: 1 addition & 0 deletions exporter/azureblobexporter/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../../Makefile.Common
63 changes: 63 additions & 0 deletions exporter/azureblobexporter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Azure Blob Exporter for OpenTelemetry Collector

<!-- status autogenerated section -->

<!-- status autogenerated section -->
| Status | |
| ------------- |-----------|
| Stability | [development]: traces, metrics, logs |
| Distributions | [contrib] |
| Issues | [![Open issues](https://img.shields.io/github/issues-search/open-telemetry/opentelemetry-collector-contrib?query=is%3Aissue%20is%3Aopen%20label%3Aexporter%2Fazureblob%20&label=open&color=orange&logo=opentelemetry)](https://github.com/open-telemetry/opentelemetry-collector-contrib/issues?q=is%3Aopen+is%3Aissue+label%3Aexporter%2Fazureblob) [![Closed issues](https://img.shields.io/github/issues-search/open-telemetry/opentelemetry-collector-contrib?query=is%3Aissue%20is%3Aclosed%20label%3Aexporter%2Fazureblob%20&label=closed&color=blue&logo=opentelemetry)](https://github.com/open-telemetry/opentelemetry-collector-contrib/issues?q=is%3Aclosed+is%3Aissue+label%3Aexporter%2Fazureblob) |
| [Code Owners](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/CONTRIBUTING.md#becoming-a-code-owner) | [@hgaol](https://www.github.com/hgaol) |

[development]: https://github.com/open-telemetry/opentelemetry-collector#development

<!-- end autogenerated section -->

## Configuration

The following settings are required:

- url: Must be specified if auth type is not connection_string. If auth type is connection_string, it's optional or will be override by the auth.connection_string. Azure storage account endpoint. e.g. https://<account-name>.blob.core.windows.net/
- auth (no default): Authentication method for exporter to ingest data.
- type (no default): Authentication type for expoter. supported values are: connection_string, service_principal, system_managed_identity, user_managed_identity and etc.
- tenand_id: Tenand Id for the client, only needed when type is service_principal.
- client_id: Client Id for the auth, only needed when type is service_principal and user_managed_identity.
- client_secret: Secret for the client, only needed when type is service_principal.
- connection_string: Connection string to the endpoint. Only needed for connection_string auth type. Once provided, it'll **override** the `url` parameter to the storage account.


The following settings can be optionally configured and have default values:

- container: container for metrics, logs and traces.
- metrics (default `metrics`): container to store metrics. default value is `metrics`.
- logs (default `logs`): container to store logs. default value is `logs`.
- traces (default `traces`): container to store traces. default value is `traces`.
- blob_name_format:
- format (default `{{.Year}}/{{.Month}}/{{.Day}}/{{.BlobName}}_{{.Hour}}_{{.Minute}}_{{.Second}}_{{.SerialNum}}.{{.FileExtension}}`): blob name format.
- blob_name: value of `BlobName`.
- metrics (default `metrics`): default is `metrics`.
- traces (default is `traces`): default is `traces`.
- logs (default is `logs`): default is `logs`.
- year (default `2006`): The date format follows constants in Golang, refer [here](https://go.dev/src/time/format.go).
- month (default `01`): similar as year.
- day (default `02`): similar as year.
- hour (default `15`): similar as year.
- minute (default `04`): similar as year.
- second (default `05`): similar as year.
- format (default `json`): `json` or `proto`. which present otel json or otel protobuf format, the file extension will be `json` or `pb`.
- encoding (default none): if specified, uses an encoding extension to encode telemetry data. Overrides format.

An example configuration is provided as follows:

```yaml
azureblobexporter:
url: "https://<your-account>.blob.core.windows.net/"
container:
logs: "logs"
metrics: "metrics"
traces: "traces"
auth:
type: "connection_string"
connection_string: "DefaultEndpointsProtocol=https;AccountName=<your-acount>;AccountKey=<account-key>;EndpointSuffix=core.windows.net"
```
93 changes: 93 additions & 0 deletions exporter/azureblobexporter/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package azureblobexporter // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/azureblobexporter"

import (
"errors"

"go.opentelemetry.io/collector/component"
)

type TelemetryConfig struct {
Logs string `mapstructure:"logs"`
Metrics string `mapstructure:"metrics"`
Traces string `mapstructure:"traces"`
}

type Container TelemetryConfig
type BlobName TelemetryConfig

type BlobNameFormat struct {
FormatType string `mapstructure:"format"`
BlobName *BlobName `mapstructure:"blob_name"`
Year string `mapstructure:"year"`
Month string `mapstructure:"month"`
Day string `mapstructure:"day"`
Hour string `mapstructure:"hour"`
Minute string `mapstructure:"minute"`
Second string `mapstructure:"second"`
}

type Authentication struct {
// Type is the authentication type. supported values are connection_string, service_principal, system_managed_identity and user_managed_identity
Type AuthType `mapstructure:"type"`

// TenantId is the tenand id for the AAD App. It's only needed when type is service principal.
TenantId string `mapstructure:"tenant_id"`

// ClientId is the AAD Application client id. It's needed when type is service principal or user managed identity
ClientId string `mapstructure:"client_id"`
// ClientSecret only needed when auth type is service_principal

ClientSecret string `mapstructure:"client_secret"`

// ConnectionString to the endpoint.
ConnectionString string `mapstructure:"connection_string"`
}

type AuthType string

const (
ConnectionString AuthType = "connection_string"
SystemManagedIdentity AuthType = "system_managed_identity"
UserManagedIdentity AuthType = "user_managed_identity"
ServicePrincipal AuthType = "service_principal"
)

// Config contains the main configuration options for the azure storage blob exporter
type Config struct {
Url string `mapstructure:"url"`
Container *Container `mapstructure:"container"`
Auth *Authentication `mapstructure:"auth"`
BlobNameFormat *BlobNameFormat `mapstructure:"blob_name_format"`
FormatType string `mapstructure:"format"`
// Encoding to apply. If present, overrides the marshaler configuration option.
Encoding *component.ID `mapstructure:"encoding"`
}

func (c *Config) Validate() error {
if c.Url == "" && c.Auth.Type != ConnectionString {
return errors.New("url cannot be empty when auth type is not connection_string")
}

if c.Auth.Type == ConnectionString {
if c.Auth.ConnectionString == "" {
return errors.New("connection_string cannot be empty when auth type is connection_string")
}
} else if c.Auth.Type == ServicePrincipal {
if c.Auth.TenantId == "" || c.Auth.ClientId == "" || c.Auth.ClientSecret == "" {
return errors.New("tenant_id, client_id and client_secret cannot be empty when auth type is service-principal")
}
} else if c.Auth.Type == UserManagedIdentity {
if c.Auth.ClientId == "" {
return errors.New("client_id cannot be empty when auth type is user_managed_identity")
}
}

if c.FormatType != formatTypeJSON && c.FormatType != formatTypeProto {
return errors.New("unknown format type: " + c.FormatType)
}

return nil
}
Loading
Loading