简体   繁体   中英

Adding a Source to Librato Data When Sending through Segment

I am trying to figure out how to add a source to a metric in Librato when sending the information via Segment. I am using the python library and have tried creating a property for source (below) but it doesn't seem to be working properly.

Here's what I've got:

     userID = '12345'
     analytics.track(userID, 'event', {
          'value': 1,
          'integrations.Librato.source': userID
     })

I've also tried 'source' and 'Librato.source' as properties, which were referenced in Segment's documentation. Any suggestions?

Similarly for ruby, using the segment gem you can specify a source like so:

require 'analytics-ruby'

segment_token = 'asdfasdf' # The secret write key for my project

Analytics.init({
    secret: segment_token,
    #Optional error handler
    on_error: Proc.necd giw { |status, msg| print msg } })

Analytics.track(
    user_id: 123, 
    writeKey: segment_token, 
    event: 'segment.librato', 
    properties: { value: 42 }, context: { source:'my.source.name' })

You can't set the source of the Librato metric in the properties when sending from Segment, you need to send it as part of the context meta data. Librato does not accept any properties other than 'value' so nothing else you send as a property will be recorded. To set the source using the python library, the code needs to be as follows:

     userID = '12345'
     analytics.track(userID, 'event', {
          'value': 1
     }, {
          'Librato': {
               'source': userID
               }
     })

If you are are using javascript, it would be:

analytics.track({
  userId: '12345',
  event: 'event'
  properties: {
    value: 1
  },
  context: {
     'Librato': {
        'source': userID
     }
  }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM