import os
from datadog import initialize

traptor_type = os.environ['TRAPTOR_TYPE']
traptor_id = os.environ['TRAPTOR_ID']

DEFAULT_TAGS = [
    'traptor_type:{}'.format(traptor_type),
    'traptor_id:{}'.format(traptor_id),
]

options = {
    'statsd_host': os.environ['STATSD_HOST_IP'],
}
initialize(**options)


from datadog import statsd
DATADOG_METRICS = {
    'tweet_process_success': 'traptor.src.tweet_process.success',
    'tweet_process_failure': 'traptor.src.tweet_process.failure',
    'tweet_to_kafka_success': 'traptor.src.tweet_to_kafka.success',
    'tweet_to_kafka_failure': 'traptor.src.tweet_to_kafka.failure',
}

def increment(metric_name):
    return statsd.increment(DATADOG_METRICS[metric_name], tags=DEFAULT_TAGS)

def gauge(metric_name, value):
    return statsd.gauge(DATADOG_METRICS[metric_name], value, tags=DEFAULT_TAGS)

import os
from datadog import initialize

traptor_type = os.getenv('TRAPTOR_TYPE', 'track')
traptor_id = os.getenv('TRAPTOR_ID', '0')

DEFAULT_TAGS = [
    'traptor_type:{}'.format(traptor_type),
    'traptor_id:{}'.format(traptor_id),
]

options = {
    'statsd_host': os.getenv('STATSD_HOST_IP', '127.0.0.1')
}
initialize(**options)


from datadog import statsd
DATADOG_METRICS = {
    'tweet_process_success': 'traptor.src.tweet_process.success',
    'tweet_process_failure': 'traptor.src.tweet_process.failure',
    'tweet_to_kafka_success': 'traptor.src.tweet_to_kafka.success',
    'tweet_to_kafka_failure': 'traptor.src.tweet_to_kafka.failure',
}

def increment(metric_name):
    return statsd.increment(DATADOG_METRICS[metric_name], tags=DEFAULT_TAGS)

def gauge(metric_name, value):
    return statsd.gauge(DATADOG_METRICS[metric_name], value, tags=DEFAULT_TAGS)

Use getenv instead of environment dict
Use getenv instead of environment dict

  import os
  from datadog import initialize
  
- traptor_type = os.environ['TRAPTOR_TYPE']
+ traptor_type = os.getenv('TRAPTOR_TYPE', 'track')
- traptor_id = os.environ['TRAPTOR_ID']
+ traptor_id = os.getenv('TRAPTOR_ID', '0')
  
  DEFAULT_TAGS = [
      'traptor_type:{}'.format(traptor_type),
      'traptor_id:{}'.format(traptor_id),
  ]
  
  options = {
-     'statsd_host': os.environ['STATSD_HOST_IP'],
+     'statsd_host': os.getenv('STATSD_HOST_IP', '127.0.0.1')
  }
  initialize(**options)
  
  
  from datadog import statsd
  DATADOG_METRICS = {
      'tweet_process_success': 'traptor.src.tweet_process.success',
      'tweet_process_failure': 'traptor.src.tweet_process.failure',
      'tweet_to_kafka_success': 'traptor.src.tweet_to_kafka.success',
      'tweet_to_kafka_failure': 'traptor.src.tweet_to_kafka.failure',
  }
  
  def increment(metric_name):
      return statsd.increment(DATADOG_METRICS[metric_name], tags=DEFAULT_TAGS)
  
  def gauge(metric_name, value):
      return statsd.gauge(DATADOG_METRICS[metric_name], value, tags=DEFAULT_TAGS)
  
Use getenv instead of environment dict
## Code Before:
import os
from datadog import initialize

traptor_type = os.environ['TRAPTOR_TYPE']
traptor_id = os.environ['TRAPTOR_ID']

DEFAULT_TAGS = [
    'traptor_type:{}'.format(traptor_type),
    'traptor_id:{}'.format(traptor_id),
]

options = {
    'statsd_host': os.environ['STATSD_HOST_IP'],
}
initialize(**options)


from datadog import statsd
DATADOG_METRICS = {
    'tweet_process_success': 'traptor.src.tweet_process.success',
    'tweet_process_failure': 'traptor.src.tweet_process.failure',
    'tweet_to_kafka_success': 'traptor.src.tweet_to_kafka.success',
    'tweet_to_kafka_failure': 'traptor.src.tweet_to_kafka.failure',
}

def increment(metric_name):
    return statsd.increment(DATADOG_METRICS[metric_name], tags=DEFAULT_TAGS)

def gauge(metric_name, value):
    return statsd.gauge(DATADOG_METRICS[metric_name], value, tags=DEFAULT_TAGS)

## Instruction:
Use getenv instead of environment dict
## Code After:
import os
from datadog import initialize

traptor_type = os.getenv('TRAPTOR_TYPE', 'track')
traptor_id = os.getenv('TRAPTOR_ID', '0')

DEFAULT_TAGS = [
    'traptor_type:{}'.format(traptor_type),
    'traptor_id:{}'.format(traptor_id),
]

options = {
    'statsd_host': os.getenv('STATSD_HOST_IP', '127.0.0.1')
}
initialize(**options)


from datadog import statsd
DATADOG_METRICS = {
    'tweet_process_success': 'traptor.src.tweet_process.success',
    'tweet_process_failure': 'traptor.src.tweet_process.failure',
    'tweet_to_kafka_success': 'traptor.src.tweet_to_kafka.success',
    'tweet_to_kafka_failure': 'traptor.src.tweet_to_kafka.failure',
}

def increment(metric_name):
    return statsd.increment(DATADOG_METRICS[metric_name], tags=DEFAULT_TAGS)

def gauge(metric_name, value):
    return statsd.gauge(DATADOG_METRICS[metric_name], value, tags=DEFAULT_TAGS)
