Skip to content

Commit

Permalink
chore: env var eval project (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-statsig authored Oct 10, 2024
1 parent 3e95abb commit 835566a
Show file tree
Hide file tree
Showing 17 changed files with 46 additions and 38 deletions.
3 changes: 2 additions & 1 deletion benchmarking/dotnet/dotnet/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
using Statsig;
using Statsig.Server;

var statsig = await StatsigServer.Initialize("secret-9IWfdzNwExEYHEW4YfOQcFZ4xreZyFkbOXHaNbPsMwW");
var secret = Environment.GetEnvironmentVariable("test_api_key");
var statsig = await StatsigServer.Initialize(secret);

var watch = Stopwatch.StartNew();

Expand Down
3 changes: 2 additions & 1 deletion benchmarking/hello_world/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use std::time::Instant;

#[tokio::main]
async fn main() {
Statsig::initialize("secret-9IWfdzNwExEYHEW4YfOQcFZ4xreZyFkbOXHaNbPsMwW").await;
let secret_key = env::var("test_api_key").expect("test_api_key must be set");
Statsig::initialize(secret_key).await;

let start = Instant::now();
let mut init_res = String::new();
Expand Down
2 changes: 1 addition & 1 deletion benchmarking/node/pure.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const email = "[email protected]";

const user = { userID: name, email };

Statsig.initialize("secret-9IWfdzNwExEYHEW4YfOQcFZ4xreZyFkbOXHaNbPsMwW").then(
Statsig.initialize(process.env.test_api_key).then(
() => {
const gate_name = "test_public";

Expand Down
5 changes: 3 additions & 2 deletions benchmarking/pure.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import os

from time import perf_counter
from statsig import statsig, StatsigUser


statsig.initialize("secret-9IWfdzNwExEYHEW4YfOQcFZ4xreZyFkbOXHaNbPsMwW")
statsig_secret = os.environ.get('test_api_key')
statsig.initialize(statsig_secret)

user = StatsigUser("Dan")

Expand Down
4 changes: 3 additions & 1 deletion benchmarking/pure.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
require 'statsig'
require 'benchmark'

Statsig.initialize('secret-9IWfdzNwExEYHEW4YfOQcFZ4xreZyFkbOXHaNbPsMwW')
secret = ENV['test_api_key']
Statsig.initialize(secret)

user = StatsigUser.new({'userID' => 'Dan'})

time = Benchmark.measure {
init_res = {}
1000.times do
init_res = Statsig.get_client_initialize_response(user)

end
puts "Client init res: #{init_res}"
}
Expand Down
19 changes: 3 additions & 16 deletions examples/dotnet/dotnet/Program.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,7 @@
using System.Diagnostics;
using StatsigServer;

// var statsig = await StatsigServer.Create("secret-9IWfdzNwExEYHEW4YfOQcFZ4xreZyFkbOXHaNbPsMwW");
//
// var watch = Stopwatch.StartNew();
//
// var result = "";
// for (var i = 0; i < 1000; i++)
// {
// var user = new User("user_" + i, "[email protected]");
// var exp = statsig.GetExperiment(user, "running_exp_in_unlayered_with_holdout");
// result = statsig.GetClientInitResponse(user);
// }
//
// watch.Stop();
//
// statsig.Dispose();


void Foo()
{
Expand All @@ -33,7 +19,8 @@ void Foo()
async Task Bar()
{
var options = new StatsigOptions();
var statsig = new Statsig("secret-9IWfdzNwExEYHEW4YfOQcFZ4xreZyFkbOXHaNbPsMwW", options);
var sdkKey = Environment.GetEnvironmentVariable("test_api_key");
var statsig = new Statsig(sdkKey, options);
await statsig.Initialize();

var user = new StatsigUser("a-user", "[email protected]");
Expand Down
2 changes: 1 addition & 1 deletion examples/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
email = "[email protected]"

user = User(user_id, email)
statsig = Statsig("secret-9IWfdzNwExEYHEW4YfOQcFZ4xreZyFkbOXHaNbPsMwW")
statsig = Statsig(os.environ['test_api_key'])

gate_name = "test_public"

Expand Down
2 changes: 1 addition & 1 deletion examples/example.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
email = "[email protected]"

user = User.create(name, email)
statsig = Statsig.for_user(user, "secret-9IWfdzNwExEYHEW4YfOQcFZ4xreZyFkbOXHaNbPsMwW")
statsig = Statsig.for_user(user, ENV['test_api_key'])

# gate_name = "example_gate"
# result = statsig.check_gate(gate_name)
Expand Down
4 changes: 3 additions & 1 deletion examples/go/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"fmt"
"time"
"os"

"statsig.com/sdk/statsig"
)
Expand All @@ -14,7 +15,8 @@ func main() {
user := statsig.NewUser(name, email)
defer user.Destroy()

statsigInstance := statsig.NewStatsig(user, "secret-9IWfdzNwExEYHEW4YfOQcFZ4xreZyFkbOXHaNbPsMwW")
sdkKey := os.Getenv("test_api_key")
statsigInstance := statsig.NewStatsig(user, sdkKey)
defer statsigInstance.Destroy()

// gateName := "test_public"
Expand Down
3 changes: 2 additions & 1 deletion examples/java/src/main/java/example/statsig/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
public class Main {
public static void main(String[] args) throws ExecutionException, InterruptedException {
StatsigOptions options = new StatsigOptions.Builder().setOutputLoggerLevel(OutputLogger.LogLevel.DEBUG).build();
Statsig statsig = new Statsig("secret-9IWfdzNwExEYHEW4YfOQcFZ4xreZyFkbOXHaNbPsMwW", options);
String sdkKey = System.getenv("test_api_key");
Statsig statsig = new Statsig(sdkKey, options);

statsig.initialize().get();

Expand Down
2 changes: 1 addition & 1 deletion examples/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ int main() {

CUser* user = create_user(name, email);

const char* sdk_key = "secret-9IWfdzNwExEYHEW4YfOQcFZ4xreZyFkbOXHaNbPsMwW";
const char* sdk_key = getenv("test_api_key");
Statsig* statsig = initialize_statsig(sdk_key);

const char* gate_name = "test_public";
Expand Down
2 changes: 1 addition & 1 deletion examples/node/example.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Statsig, StatsigOptions, StatsigUser } from "statsig-napi";

const statsig = new Statsig(
"secret-9IWfdzNwExEYHEW4YfOQcFZ4xreZyFkbOXHaNbPsMwW",
process.env.test_api_key,
{}
);

Expand Down
3 changes: 2 additions & 1 deletion examples/php/src/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
use Statsig\StatsigFFI\Statsig;
use Statsig\StatsigFFI\StatsigUser;

$statsig = new Statsig("secret-9IWfdzNwExEYHEW4YfOQcFZ4xreZyFkbOXHaNbPsMwW");
$secret_key = getenv('test_api_key');
$statsig = new Statsig($secret_key);
$statsig->initialize(function () use ($statsig) {
$user = new StatsigUser("a-user", "[email protected]");
$gcir = $statsig->getClientInitializeResponse($user);
Expand Down
5 changes: 4 additions & 1 deletion examples/rust/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::sync::Arc;
use tokio::time::{sleep, Duration};
use sigstat::{LogLevel, Statsig, StatsigOptions, StatsigUser};
use std::env;

#[tokio::main]
async fn main() {
Expand All @@ -9,7 +10,9 @@ async fn main() {
..StatsigOptions::new()
});

let statsig = Statsig::new("secret-9IWfdzNwExEYHEW4YfOQcFZ4xreZyFkbOXHaNbPsMwW", Some(opts));
let sdk_key = env::var("test_api_key").expect("test_api_key environment variable not set");

let statsig = Statsig::new(sdk_key, Some(opts));
let _ = statsig.initialize().await;
let user = StatsigUser::with_user_id("a-user".to_string());
loop {
Expand Down
2 changes: 1 addition & 1 deletion statsig-ffi/bindings/node/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ function statsig_create(sdkKey, optionsRef) {
}

const statsig = statsig_create(
'secret-9IWfdzNwExEYHEW4YfOQcFZ4xreZyFkbOXHaNbPsMwW',
process.env.test_api_key,
options,
);
console.log('[JS]: statsig_create', statsig);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,17 @@ impl EventLoggingAdapter for StatsigEventLoggingAdapter {
}
}



#[tokio::test]
async fn test_event_logging() {
use std::env;

let adapter = StatsigEventLoggingAdapter::new();
let sdk_key = env::var("test_api_key").expect("test_api_key environment variable not set");

adapter.bind(
"secret-IiDuNzovZ5z9x75BEjyZ4Y2evYa94CJ9zNtDViKBVdv",
&sdk_key,
&StatsigOptions::new(),
);

Expand Down
15 changes: 9 additions & 6 deletions statsig-lib/src/statsig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -596,8 +596,11 @@ fn create_runtime_if_required() -> (Option<Runtime>, Handle) {
mod tests {
use super::*;
use crate::{evaluation::evaluation_types::AnyConfigEvaluation, StatsigHttpIdListsAdapter};
use std::env;

const SDK_KEY: &str = "secret-9IWfdzNwExEYHEW4YfOQcFZ4xreZyFkbOXHaNbPsMwW";
fn get_sdk_key() -> String {
env::var("test_api_key").expect("test_api_key environment variable not set")
}

#[tokio::test]
async fn test_check_gate() {
Expand All @@ -606,7 +609,7 @@ mod tests {
..StatsigUser::with_user_id("a-user".to_string())
};

let statsig = Statsig::new(SDK_KEY, None);
let statsig = Statsig::new(&get_sdk_key(), None);
statsig.initialize().await.unwrap();

let gate_result = statsig.check_gate(&user, "test_50_50");
Expand All @@ -627,10 +630,10 @@ mod tests {

let mut opts = StatsigOptions::new();

let adapter = Arc::new(StatsigHttpIdListsAdapter::new(SDK_KEY, &opts));
let adapter = Arc::new(StatsigHttpIdListsAdapter::new(&get_sdk_key(), &opts));
opts.id_lists_adapter = Some(adapter);

let statsig = Statsig::new(SDK_KEY, Some(Arc::new(opts)));
let statsig = Statsig::new(&get_sdk_key(), Some(Arc::new(opts)));
statsig.initialize().await.unwrap();

let gate_result = statsig.check_gate(&user, "test_id_list");
Expand All @@ -645,7 +648,7 @@ mod tests {
..StatsigUser::with_user_id("a-user".to_string())
};

let statsig = Statsig::new(SDK_KEY, None);
let statsig = Statsig::new(&get_sdk_key(), None);
statsig.initialize().await.unwrap();

let experiment = statsig.get_experiment(&user, "running_exp_in_unlayered_with_holdout");
Expand All @@ -664,7 +667,7 @@ mod tests {
..StatsigOptions::new()
};

let statsig = Statsig::new(SDK_KEY, Some(Arc::new(opts)));
let statsig = Statsig::new(&get_sdk_key(), Some(Arc::new(opts)));
statsig.initialize().await.unwrap();

let response = statsig.get_client_init_response(&user);
Expand Down

0 comments on commit 835566a

Please sign in to comment.