Skip to content

Conversation

@alexcams
Copy link
Contributor

@alexcams alexcams commented Nov 5, 2025

Description

Added new ottl function delete_index(target, startIndex, Optional[endIndex]

The delete_index function removes elements from a slice. It deletes elements in the range [startIndex, endIndex) (startIndex inclusive, endIndex exclusive). If endIndex is not provided, only the element at target[startIndex] is deleted. If startIndex equals endIndex, no changes are applied to the target, following the behavior of Go's slices.Delete(s, i, j) function.

It accepts any OTTL array type, including arrays with different type of data.
Implemented this as a function modifying target rather than converter returning merged arrays
This implementation doesn't delete duplicate values, could be added in the future or implemented as a separated function.

Note Following golang Slices.Delete() function behavior, any case where index out of bouds ( i < 0 || (i+len) > size(slice)) will return an error.

Link to tracking issue

Closes #43098

Testing

Added unit tests with intended behavior.
Tested manually with following config:

receivers:
  filelog:
    include: [ test.log ]
    start_at: beginning

exporters:
  debug:
    verbosity: detailed
    sampling_initial: 10000
    sampling_thereafter: 10000

processors:
  transform:
    error_mode: ignore
    log_statements:
      - context: log
        statements: 
          - set(attributes["test"], [[1, 2, 3, 4]]) # init slice with nested slice
          - append(attributes["test"], values = ["val", 1, true, 3.14, "foo", "foo", 2, false, 6.28]) # append multiple values
          - set(attributes["test_copy"], attributes["test"]) # make a copy 
          - delete_index(attributes["test"], 1) # delete "val"
          - delete_index(attributes["test"], Len(attributes["test"]) - 1) # delete last element (6,28)
          - delete_index(attributes["test"], Index(attributes["test"], "foo")) # delete "foo" first instance
          - delete_index(attributes["test_copy"], 0, endIndex=4) # delete first 4 elements from copy

service:
  telemetry:
    metrics:
      level: none
  pipelines:
    logs:
      receivers: [filelog]
      processors: [transform]
      exporters:
        - debug

Output:

Body: Str(2025-11-05 10:00:00 INFO Test log message)
Attributes:
     -> log.file.name: Str(test.log)
     -> test: Slice([[1,2,3,4],1,true,3.14,"foo",2,false])
     -> test_copy: Slice([3.14,"foo","foo",2,false,6.28])

Documentation

Updated README.md

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Nov 5, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: evan-bradley / name: Evan Bradley (85ba8d6)

@github-actions github-actions bot added the first-time contributor PRs made by new contributors label Nov 5, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Nov 5, 2025

Welcome, contributor! Thank you for your contribution to opentelemetry-collector-contrib.

Important reminders:

A maintainer will review your pull request soon. Thank you for helping make OpenTelemetry better!

@alexcams alexcams marked this pull request as draft November 5, 2025 08:49
@alexcams alexcams force-pushed the add-ottl-delete-elemelt-function branch from 25a241a to fe95cef Compare November 5, 2025 09:48
@alexcams alexcams marked this pull request as ready for review November 5, 2025 09:48
@alexcams
Copy link
Contributor Author

alexcams commented Nov 5, 2025

Last commit updates the first implemented algorithm to a new one that avoids the use of AsRaw() and FromRaw() functions, both of cost O(N). Instead it is replaces by a single loop O(N) and preallocating memory for the result slice.
Here's a comparative between both algorithms showing that the second one reduces time and memory spent for different scenarios by 50% (at least).
image

@alexcams alexcams marked this pull request as draft November 19, 2025 16:47
@alexcams alexcams force-pushed the add-ottl-delete-elemelt-function branch from 55d8843 to 316040b Compare December 9, 2025 09:13
@alexcams alexcams marked this pull request as ready for review December 9, 2025 09:27
@alexcams alexcams force-pushed the add-ottl-delete-elemelt-function branch from d68385d to e3262c8 Compare December 12, 2025 10:49
@alexcams alexcams force-pushed the add-ottl-delete-elemelt-function branch 3 times, most recently from d7ee9cf to d391aad Compare December 15, 2025 14:54
@alexcams alexcams force-pushed the add-ottl-delete-elemelt-function branch from d391aad to b27591a Compare December 16, 2025 12:17
@edmocosta
Copy link
Contributor

edmocosta commented Dec 16, 2025

@TylerHelmuth @evan-bradley @bogdandrutu Please take a look once you get a chance. Thanks!

Co-authored-by: Edmo Vamerlatti Costa <11836452+edmocosta@users.noreply.github.com>
@github-actions
Copy link
Contributor

This PR was marked stale due to lack of activity. It will be closed in 14 days.

@evan-bradley
Copy link
Contributor

Sorry for the delay @alexcams. We are determining how we want to name this function, and there are extra considerations involved in which name we ultimately go with. @edmocosta or I will give you an update as soon as we are able.

@alexcams
Copy link
Contributor Author

@evan-bradley Don't worry :) Naming can be challenging sometimes and I think delete is too generic for a function that just deletes elements from slices. I'm here for any doubt!

@edmocosta
Copy link
Contributor

Hi @alexcams! Just to give you some context, we're considering a few renaming/standardization for slices/maps functions, but to not delay this PR that much, we agreed on the delete_index name. It's a bit more specific, and we can tackle the standardization later with the other functions. Thanks!

@alexcams alexcams requested a review from edmocosta January 20, 2026 10:07
@alexcams
Copy link
Contributor Author

/rerun

@alexcams alexcams requested a review from edmocosta January 20, 2026 13:20
Copy link
Contributor

@evan-bradley evan-bradley left a comment

Choose a reason for hiding this comment

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

Thanks @alexcams!

@evan-bradley evan-bradley merged commit 733bcf4 into open-telemetry:main Jan 26, 2026
191 checks passed
@otelbot
Copy link
Contributor

otelbot bot commented Jan 26, 2026

Thank you for your contribution @alexcams! 🎉 We would like to hear from you about your experience contributing to OpenTelemetry by taking a few minutes to fill out this survey. If you are getting started contributing, you can also join the CNCF Slack channel #opentelemetry-new-contributors to ask for guidance and get help.

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.

[pkg/ottl] add a function to remove an element from a Slice/Array

6 participants