Skip to content

Add support for dynamic index in OpenSearch exporter #40530

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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

ps48
Copy link

@ps48 ps48 commented Jun 6, 2025

Support for Dynamic Log Indexing in OpenSearch

This PR supports dynamic log index names using placeholders in the logs_index config. You can use any attribute or context key as a placeholder to construct index names dynamically per log record.

logs_index

  • Placeholder: %{key}

    • Example: otel-logs-%{service.name} or otel-logs-%{custom.label}
    • The value is looked up from a context map (resource attributes, log attributes, etc.).
    • If the key is missing, the value from logs_index_fallback is used (or unknown if not set).
  • If logs_index is not set, the exporter will use the default naming pattern: ss4o_{type}-{dataset}-{namespace} (e.g., ss4o_logs-default-namespace). This ensures backward compatibility and a predictable index naming scheme.

logs_index_time_format

You can append a time-formatted suffix to the index name using the logs_index_time_format option.

  • logs_index_time_format: If set, appends a time suffix to the resolved index name using the specified format (default is no suffix).
  • Valid tokens (case-sensitive):
    • yyyy (4-digit year)
    • yy (2-digit year)
    • MM (2-digit month)
    • dd (2-digit day)
    • HH (2-digit hour, 24h)
    • mm (2-digit minute)
    • ss (2-digit second)
  • Allowed separators: -, ., _, +
  • Examples:
    • yyyy.MM.dd2024.06.07
    • yyyy-MM2024-06
    • yyMMdd240607
    • yyyy_MM_dd+HH2024_06_07+15
  • Any other characters or tokens will result in a configuration error.

Link to tracking issue

#34746
#38595

Testing

Unit tests for parsing and rendering logs_index, logs_index_fallback, and logs_index_time_format. Integration tests against a local OpenSearch instance to verify index names (including fallbacks and timestamp formatting).

Documentation

Updated exporter/opensearchexporter/README.md

Example Configuration
exporters:
  opensearch:
    http:
      endpoint: http://opensearch.example.com:9200
    logs_index: "otel-logs-%{service.name}"
    logs_index_fallback: "default-service" # optional, if not set default is `unknown`
    logs_index_time_format: "yyyy.MM.dd" # optional, if set appends time suffix

@ps48 ps48 marked this pull request as ready for review June 7, 2025 03:30
@ps48 ps48 requested a review from a team as a code owner June 7, 2025 03:30
@ps48 ps48 requested a review from andrzej-stencel June 7, 2025 03:30
Copy link
Member

@andrzej-stencel andrzej-stencel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just minor non-blocking comments.

Copy link

linux-foundation-easycla bot commented Jun 16, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

@ps48
Copy link
Author

ps48 commented Jun 16, 2025

Hi @andrzej-stencel, Thanks for review. We have made the abovementioned changes in this PR. Can you please take a look and help us merge this PR? Thanks again!

@songy23
Copy link
Member

songy23 commented Jun 16, 2025

Generated code is out of date, please run "make generate" and commit the changes in this PR.

Copy link

@KarstenSchnitter KarstenSchnitter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for providing this feature. I think the documentation can be improved as can be the performance impact in case the feature is not used.

errNamespaceNoValue = errors.New("namespace must be specified")
errBulkActionInvalid = errors.New("bulk_action can either be `create` or `index`")
errMappingModeInvalid = errors.New("mapping.mode is invalid")
errLogsIndexInvalidPlaceholder = errors.New("logs_index cannot have two attribute or context key placeholders")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can it be more than 2 attributes or placeholders for this message to be used?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see the message is not clear. Changed this to logs_index can only have one placeholder. 346f05a

startErr := indexer.start(l.client)
if startErr != nil {
return startErr
}

// Collect attributes from resource/log record
attrs := collectAttributes(ld)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you not do that, if no LogsIndex is set? You do not need the data structure in that case.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great catch. updated this line and moved it only if the logs_index config is set: 346f05a

@ps48
Copy link
Author

ps48 commented Jun 17, 2025

Generated code is out of date, please run "make generate" and commit the changes in this PR.

Thanks @songy23 updated the autogen file here: 682c6a9

@ps48
Copy link
Author

ps48 commented Jun 20, 2025

Hi @andrzej-stencel @KarstenSchnitter, Please let me know if there are any other changes needed here. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants