Comments (14)
The object + set
implies full overwrite instead of merge to me
from apm-agent-nodejs.
If you make setTag
an alias for setTags({ key: value })
I see no reason to deprecate it.
will calling setTags multiple times just add to the list of tags?
I would guess that I would expect this behaviour but maybe it should be addTags
then. what happens now if you call setTag
twice?
from apm-agent-nodejs.
@AdriVanHoudt calling setTag
twice with the same key overwrites the old value. Calling it with different keys just sets the values for those, but still keeps the other tags
from apm-agent-nodejs.
I see, maybe this makes more sense then
agent.setTags([key1, 'value'], [key2, 'value'])
// or
agent.setTags([[key1, 'value'], [key2, 'value']])
from apm-agent-nodejs.
@AdriVanHoudt what's your use-case for using arrays to specify key/value pairs instead of a flat object?
from apm-agent-nodejs.
cc @elastic/apm-agent-devs
from apm-agent-nodejs.
I'd go with a plain object. That array form seems a bit less friendly to the end-user, and you can get that with Object.entries()
anyway, if you really need it.
from apm-agent-nodejs.
Maybe keep the way it works but call it assign
or merge
as that is what it actually does - JavaScript-wise?
from apm-agent-nodejs.
There seems to be a consensus that:
- It should be possible to assign tags to a transaction multiple times during the transaction lifetime
- It should be possible to overwrite a specific tag with a new value
- Setting tags a second time during the same transaction, shouldn't remove the tags set previously on the same transaction
- The function name
setTags
doesn't convey the intend of point no 3
I'm not sure that I like assignTags
. Not sure why, but it just seems weird to me even though that's what used for Object.assign
etc. I personally prefer addTags
better, and I think that it's fairly obvious that calling addTags
twice with the same key, will overwrite the value of said key.
So how about this:
// starting out, there's no tags at all
agent.addTags({tag1: 'foo', tag2: 'bar'}) // now there's two tags: tag1 + tag2
agent.addTags({tag1: 42, tag3: 'baz'}) // now there's three tags: tag1 + tag2 + tag3
You could argue that it's not obvious that the tags set are scoped to the current transaction and that you should spell it out like agent.setTransactionTags()
?
What do you think of this (either setTags
or setTransactionTags
)?
from apm-agent-nodejs.
I haven't implemented it yet, but I'm considering if tags set during a transaction should also be applied to exceptions/messages that happen during that transaction. There isn't really a way to tag "unhandled" exceptions in any other way AFAICT. In that case, setTransactionTags
would be a bit of a misnomer.
from apm-agent-nodejs.
I wonder how reasonable it'd be to have something like agent.currentTransaction
so one could do agent.currentTransaction.setTags(...)
and have it apply to that transaction. In that way, it's clear it applies specifically to the transaction object and also provides a mechanism for further transaction-specific interfaces.
from apm-agent-nodejs.
@beniwohli Brainstorming: How if we had some way to simply link errors to a transaction? E.g. attach the transaction id of the transaction that was active when the error occurred along with the error
@Qard Good idea. I've been considering something similar in other scenarios. The reason why I've so far not implemented something like that is because I haven't found a good way to handle the case where there isn't a current transaction. I don't want to add if (agent.currentTransaction) ...
all over the place. I've been thinking about defining it as getter property so it can return a dummy transaction if none is there, but that also have its own set of problems. But I haven't spent too much time trying to solve this, so there might be a good way that I haven't thought of.
from apm-agent-nodejs.
Maybe some sort of get-or-create thing? Something like agent.getOrStartTransaction(...)
could work.
from apm-agent-nodejs.
@Qard I think with for instance addTags()
we'll not want to do anything if there isn't currently an active transaction. It could be that instrumentation have been disabled, or we're sampling and this current request hasn't been chosen as a sample, or simply that there's a bug where we have lost context due to an un-patched async operation. We have have the same issue with agent.buildSpan()
btw, this will return null
instead of a span if there isn't an active transaction so all subsequent calls to span.*
needs to have a guard before it. So it would be cool if we could find a solution to this that made the API simpler to work with 😃
from apm-agent-nodejs.
Related Issues (20)
- recent addition of aws sqs instrumentation causing runtime failures when enabled HOT 4
- Does the "Sending error to Elastic APM: %o'" message need to be INFO level? HOT 2
- Control which framework/technology transactions are created from HOT 3
- Add configuration option to allow injecting headers on all outgoing requests
- chore: proper fallback value for boolean "bogus" options
- Error thrown when using `@elastic/ecs-pino-format` v1.4.0 HOT 3
- ESM instrumentation/hooking fails with Node.js v18.19.0 HOT 3
- update-tav-versions.js needs update for tav@5 syntax
- update Lambda guide to point out ELASTIC_APM_API_KEY for Elastic serverless usage
- Elastic APM Node package 3.50.0 and above causing issues with file upload HOT 1
- Agent environment not set correctly from NODE_ENV in 4.3.0 HOT 3
- avoid instrumenting some Node.js apps when `NODE_OPTIONS=-r elastic-apm-node/start` is being used
- "pg/knex.test.js" fails with Node.js v18.19.0 HOT 2
- Failed to start typescript app with APM agent. HOT 1
- elastic-apm-node not working for mongoose 8.0.3 and mongodb 6.2.0 HOT 1
- support `node --enable-source-maps` usage with our custom `Error.prepareStackTrace` usage
- fix <database>.$cmd.getMore span on mongodb
- Memory usage reported incorrectly in k8s pod HOT 3
- Support of Next js ^14 HOT 2
- `_signalLambdaEnd` request to Lambda extension should set `Content-Type`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from apm-agent-nodejs.