<commit_before>package js

import (
	log "github.com/Sirupsen/logrus"
	"gopkg.in/olebedev/go-duktape.v2"
)

type apiFunc func(r *Runner, c *duktape.Context) int

func apiHTTPDo(r *Runner, c *duktape.Context) int {
	method := argString(c, 0)
	if method == "" {
		log.Error("Missing method in http call")
		return 0
	}

	url := argString(c, 1)
	if url == "" {
		log.Error("Missing URL in http call")
		return 0
	}

	body := ""
	switch c.GetType(2) {
	case duktape.TypeNone, duktape.TypeNull, duktape.TypeUndefined:
	case duktape.TypeString, duktape.TypeNumber, duktape.TypeBoolean:
		body = c.ToString(2)
	case duktape.TypeObject:
		body = c.JsonEncode(2)
	default:
		log.Error("Unknown type for request body")
		return 0
	}

	args := httpArgs{}
	if err := argJSON(c, 3, &args); err != nil {
		log.Error("Invalid arguments to http call")
		return 0
	}

	res, duration, err := httpDo(r.Client, method, url, body, args)
	if err != nil {
		log.WithError(err).Error("Request error")
	}
	if !args.Quiet {
		r.mDuration.Duration(duration)
	}

	pushInstance(c, res, "HTTPResponse")

	return 1
}

func apiHTTPSetMaxConnectionsPerHost(r *Runner, c *duktape.Context) int {
	num := int(argNumber(c, 0))
	if num < 1 {
		log.Error("Max connections per host must be at least 1")
		return 0
	}
	r.Client.MaxConnsPerHost = num
	return 0
}

func apiLogType(r *Runner, c *duktape.Context) int {
	kind := argString(c, 0)
	text := argString(c, 1)
	extra := map[string]interface{}{}
	if err := argJSON(c, 2, &extra); err != nil {
		log.Error("Log context is not an object")
		return 0
	}

	l := log.WithFields(log.Fields(extra))
	switch kind {<commit_msg>[fix] Log URLs with JS-based metrics<commit_after>package js

import (
	log "github.com/Sirupsen/logrus"
	"gopkg.in/olebedev/go-duktape.v2"
)

type apiFunc func(r *Runner, c *duktape.Context) int

func apiHTTPDo(r *Runner, c *duktape.Context) int {
	method := argString(c, 0)
	if method == "" {
		log.Error("Missing method in http call")
		return 0
	}

	url := argString(c, 1)
	if url == "" {
		log.Error("Missing URL in http call")
		return 0
	}

	body := ""
	switch c.GetType(2) {
	case duktape.TypeNone, duktape.TypeNull, duktape.TypeUndefined:
	case duktape.TypeString, duktape.TypeNumber, duktape.TypeBoolean:
		body = c.ToString(2)
	case duktape.TypeObject:
		body = c.JsonEncode(2)
	default:
		log.Error("Unknown type for request body")
		return 0
	}

	args := httpArgs{}
	if err := argJSON(c, 3, &args); err != nil {
		log.Error("Invalid arguments to http call")
		return 0
	}

	res, duration, err := httpDo(r.Client, method, url, body, args)
	if err != nil {
		log.WithError(err).Error("Request error")
	}
	if !args.Quiet {
		r.mDuration.WithField("url", url).Duration(duration)
	}

	pushInstance(c, res, "HTTPResponse")

	return 1
}

func apiHTTPSetMaxConnectionsPerHost(r *Runner, c *duktape.Context) int {
	num := int(argNumber(c, 0))
	if num < 1 {
		log.Error("Max connections per host must be at least 1")
		return 0
	}
	r.Client.MaxConnsPerHost = num
	return 0
}

func apiLogType(r *Runner, c *duktape.Context) int {
	kind := argString(c, 0)
	text := argString(c, 1)
	extra := map[string]interface{}{}
	if err := argJSON(c, 2, &extra); err != nil {
		log.Error("Log context is not an object")
		return 0
	}

	l := log.WithFields(log.Fields(extra))
	switch kind {
{'fraction_non_alphanumeric': 0.14475672408582654, 'fraction_numerical': 0.012692656391659111, 'mean_word_length': 3.932935916542474, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4952498', 'n_tokens_mistral': 1342, 'n_tokens_neox': 1285, 'n_words': 336}